js不能获取ip,nodejs服务器可以。下面通过访问搜狐的接口得到ip地址
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <title>JavaScript获取客户端IP[利用新浪接口]</title> </head> <body> <script src="http://pv.sohu.com/cityjson?ie=utf-8"></script> <script type="text/javascript"> document.write(returnCitySN["cip"]+','+returnCitySN["cname"]) </script> </body> </html>