This article is a mirror article of machine translation, please click here to jump to the original article.

View: 11352|Reply: 0

[JavaScript] js to obtain a simple example of the client's local and public IP addresses

[Copy link]
Posted on 2/23/2015 10:49:58 AM | | |
For example, js gets local and public IP addresses.

  1. <scrip去掉t language="javascrip去掉t" type="text/javascrip去掉t">
  2. //获取本地IP
  3. function GetLocalIPAddress()
  4. { var obj = null; var rslt = "";
  5. try{ obj = new ActiveXObject("rcbdyctl.Setting");
  6. rslt = obj.GetIPAddress; obj = null; }
  7. catch(e)
  8. { alert("ErrInfoIS:"+e) } return rslt; }
  9. document.write("你的IP是:" + GetLocalIPAddress());
  10. </scrip去掉t>
Copy code

The above is how js obtains a local IP address, let's take a look at an example of js obtaining an external IP address.


  1. <scrip去掉t language="javascrip去掉t">
  2. //获取外网IP
  3. xml=new ActiveXObject("Microsoft.XMLHTTP");
  4. xml.open("GET","http://city.ip138.com/city0.asp",false);
  5. xml.send(); kk=xml.ResponseText;
  6. i=kk.indexOf("["); ie=kk.indexOf("]");
  7. ip=kk.substring(i+1,ie); document.write("<span style='color:red;font-size:12;' cursor='hand'>您的IP地址是:" + ip + "</span>"); </scrip去掉t>
Copy code






Previous:2015 Spring Festival Gala Solitaire Poker Magic Reveal Video, do you think the magician's hands are fast enough?
Next:2015 Spring Festival Gala [Baidu Netdisk] [720P] download and watch
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com