IP Address Lookup in a Firefox Extension

做~自己de王妃 提交于 2019-12-21 05:24:16

问题


I'm writing a Firefox extension and I need to find the ip address of the currently loaded page. I can get the hostname of the page with window.location.host, but is there any way to find the ip for that hostname?

I tried looking for the answer at the Mozilla Developer Center but was unable to find anything.

EDIT: I would use something like PHP to do this, but cannot, because it's a firefox extension, running on the client side only. I have no web server to do back end PHP.


回答1:


You could look at how the ShowIP Firefox extension does it.




回答2:


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
}



回答3:


If not a PHP Lookup, do a simple nslookup, or dig for hostname string.



来源:https://stackoverflow.com/questions/1082728/ip-address-lookup-in-a-firefox-extension

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!