获取本地客户端真实IP的探讨?

webrtc\u0026lt;SCRIPT\u0026gt;\tfunction Myaddress(ip)\t{\t\tdocument.getElementById(\u0026#39;id\u0026#39;).innerHTML=ip;\t}; \tfunction getIpByActiveObject() //IE window 2000 server xp\t{\t\t//var wshNetwork = new ActiveXObject("WScript.Network"); \t\t//alert(wshNetwork.ComputerName);\t\tvar ip=new ActiveXObject("rcbdyctl.Setting").GetIPAddress;//无效代码\t\tdocument.getElementById(\u0026#39;active\u0026#39;).innerHTML=ip;\t\t}\tfunction getIP_webrtc()\t{\t\t// NOTE: window.RTCPeerConnection is "not a constructor" in FF22/23 \tvar RTCPeerConnection = /*window.RTCPeerConnection ||*/ window.webkitRTCPeerConnection || window.mozRTCPeerConnection;\t\tif (RTCPeerConnection)\t\t{ \t\t (function (){\t\t\tvar rtc = new RTCPeerConnection({iceServers:});\t\t\tif (window.mozRTCPeerConnection) \t\t\t{ // FF needs a channel/stream to proceed\t\t\t\t rtc.createDataChannel(\u0026#39;\u0026#39;, {reliable:false});\t\t\t};\t\t\trtc.onicecandidate = function (evt){\t\t\t\tif (evt.candidate) grepSDP(evt.candidate.candidate);\t\t\t };\t\t\trtc.createOffer(function (offerDesc) {\t\t\t\t//alert(1);\t\t\t\tgrepSDP(offerDesc.sdp);\t\t\t\trtc.setLocalDescription(offerDesc);\t\t\t}, function (e) { console.warn("offer failed", e); });\t\t\t//alert(1111);\t\t\tvar addrs = Object.create(null);\t\t\taddrs = false;\t\t\tfunction updateDisplay(newAddr) {\t\t\t\tif (newAddr in addrs) return;\t\t\t\telse addrs = true;\t\t\t\tvar displayAddrs = Object.keys(addrs).filter(function (k) { return addrs; });\t\t\t document.getElementById(\u0026#39;list\u0026#39;).textContent = displayAddrs.join(" or perhaps ") || "n/a";\t\t\t }\t\t\t\t\tfunction grepSDP(sdp) \t\t\t{\t\t\t\tvar hosts = ;\t\t\t\tsdp.split(\u0026#39;\\r\\u0026#39;).forEach(function (line) { \t\t\t\t\t if (~line.indexOf("a=candidate")) \t\t\t\t\t { \t\t\t\t\t\t var parts = line.split(\u0026#39; \u0026#39;); \t\t\t\t\t\t var addr = parts;\t\t\t\t\t\t var type = parts;\t\t\t\t\t\tif (type === \u0026#39;host\u0026#39;) updateDisplay(addr);\t\t\t\t\t } \t\t\t\t\t else if (~line.indexOf("c=")) \t\t\t\t\t { \t\t\t\t\t\t var parts = line.split(\u0026#39; \u0026#39;),\t\t\t\t\t\t\taddr = parts;\t\t\t\t\t\t updateDisplay(addr);\t\t\t\t\t }\t\t\t\t});//end forEach\t\t\t }//end grepSDP\t\t })();//end fuction \t\t}//if\t\telse {\t\t\tdocument.getElementById(\u0026#39;list\u0026#39;).innerHTML = "\u0026lt;code\u0026gt;ifconfig | grep inet | grep -v inet6 | cut -d\\" \\" -f2 | tail -n1\u0026lt;/code\u0026gt;";\t\t\tdocument.getElementById(\u0026#39;list\u0026#39;).nextSibling.textContent = "In Chrome and Firefox your IP should display automatically, by the power of WebRTCskull.";\t\t }}\u0026lt;/script\u0026gt;自己看着改吧!


    推荐阅读