简体   繁体   English

Firefox扩展中的IP地址查找

[英]IP Address Lookup in a Firefox Extension

I'm writing a Firefox extension and I need to find the ip address of the currently loaded page. 我正在写一个Firefox扩展,我需要找到当前加载页面的IP地址。 I can get the hostname of the page with window.location.host, but is there any way to find the ip for that hostname? 我可以使用window.location.host获取页面的主机名,但有没有办法找到该主机名的ip?

I tried looking for the answer at the Mozilla Developer Center but was unable to find anything. 我试着在Mozilla开发者中心寻找答案,但却找不到任何答案。

EDIT: I would use something like PHP to do this, but cannot, because it's a firefox extension, running on the client side only. 编辑:我会使用像PHP这样的东西,但不能,因为它是一个firefox扩展,只在客户端运行。 I have no web server to do back end PHP. 我没有Web服务器来做后端PHP。

你可以看看ShowIP Firefox扩展程序是如何做到的。

var cls = Cc['@mozilla.org/network/dns-service;1'];
var iface = Ci.nsIDNSService;
var dns = cls.getService(iface); //dns object

var nsrecord = dns.resolve(HOSTNAME_HERE, true); //resolve hostname
while (nsrecord && nsrecord.hasMore()){
   alert(nsrecord.getNextAddrAsString()); //here you are
}

如果不是PHP查找,请执行简单的nslookup,或挖掘主机名字符串。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM