JS获取客户端IP的方法
1:
<script language="JavaScript">
function GetLocalIPAddr(){
var oSetting = null;
var ip = null;
try{
oSetting = new ActiveXObject( "rcbdyctl.Setting" );
ip = oSetting.GetIPAddress;
alert(ip);
if (ip.length == 0){
return "没有连接到Internet";
}
oSetting = null;
}catch(e){
return ip;
}
return ip;
}
alert(GetLocalIPAddr())
</script>
2:
<script>
function getIP(bat,txt){
var fso=new ActiveXObject("Scripting.FileSystemObject")
var f=fso.createTextFile(bat,1);
f.writeLine("ipconfig>"+txt);
f.Close();
var wsh=new ActiveXObject("wscript.shell");
wsh.run(bat)
setTimeout(display,1000)
function display(){
var f=fso.openTextFile(txt);
alert(f.ReadAll());
f.Close();
fso.DeleteFile(bat);
fso.DeleteFile(txt);
}
}
getIP("qswhIP.bat","qswhIP.txt")
</script>
3:
<object classid=clsid:{248DD896-BB45-11CF-9ABC-0080C7E7B78D}
name=winsock></object>
<script>try{alert(winsock.localIP)}catch(e){alert("没安装该控件")}
</script>
4:
function GetLocalIPAddress()
{
var obj = null;
var rslt = "";
try
{
obj = new ActiveXObject("rcbdyctl.Setting");
rslt = obj.GetIPAddress;
obj = null;
}
catch(e)
{
//异常发生
}
return rslt;
}