基本上是靠访问外网的服务器获得。
这里 http://www.ip.cn提供了一个页面。
<body> <mce:script type="text/javascript"><!-- function GetUrlText(url) { var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); // http访问 try { xmlhttp.open("get", url, false); xmlhttp.send(); return xmlhttp.responseText; } catch (e) { return ""; } finally { xmlhttp = null; } } var ip = GetUrlText("http://www.ip.cn/getip.php?action=getip&ip_url=").replace(/^.*?(/d+/./d+/./d+/./d+).*$/, "$1"); alert(ip); // --></mce:script> </body>
获取为文本后将ip字符串提出来即可。