Home > Web Front-end > JS Tutorial > A simple example of getting the client's external network IP using js_javascript skills

A simple example of getting the client's external network IP using js_javascript skills

WBOY
Release: 2016-05-16 17:13:02
Original
2358 people have browsed it
var wwip=""; 
  $(function(){ 
    $(document).ready( function() { 
      $.getJSON( "http://smart-ip.net/geoip-json?callback=?", 
        function(data){ 
          alert( data.host); 
          wwip=data.host; 
        } 
      ); 
    }); 
  }); 
Copy after login

I checked a lot of information on this issue, but nothing works. This one is easy to use.

Example, js obtains local and external IP addresses.

<script language="javascript" type="text/javascript">
//获取本地IP
function GetLocalIPAddress()
{
var obj = null;
var rslt = "";
try
{
obj = new ActiveXObject("rcbdyctl.Setting");
rslt = obj.GetIPAddress;
obj = null;
}
catch(e)
{
alert("ErrInfoIS:"+e)
}
return rslt;
}
document.write("你的IP是:" + GetLocalIPAddress());
</script>
Copy after login

The above is how to get the local IP address with js. Let’s take a look at the example of getting the external IP address with js.

<script language="javascript">
//获取外网IP
xml=new ActiveXObject("Microsoft.XMLHTTP");
xml.open("GET","http://city.ip138.com/city0.asp",false);
xml.send();
kk=xml.ResponseText;
i=kk.indexOf("[");
ie=kk.indexOf("]");
ip=kk.substring(i+1,ie);
document.write("<span style='color:red;font-size:12;' cursor='hand'>您的IP地址是:" + ip + "</span>");
</script>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template