如何用js获取客户端IP地址

JavaScript027

如何用js获取客户端IP地址,第1张

js获取的ip地址是:自动配置的IPv4地址:

<OBJECT id=locator classid=CLSID:76A64158-CB41-11D1-8B02-00600806D9B6 VIEWASTEXT></OBJECT>

<OBJECT id=foo classid=CLSID:75718C9A-F029-11d1-A1AC-00C04FB6C223></OBJECT>

<SCRIPT language=JScript>

var service = locator.ConnectServer()

var MACAddr

var IPAddr

var DomainAddr

var sDNSName

service.Security_.ImpersonationLevel=3

service.InstancesOfAsync(foo, 'Win32_NetworkAdapterConfiguration')

</SCRIPT>

<FORM id=formfoo name=formbar action=NICPost.asp method=post>

<INPUT value=00:05:5D:0E:C7:FA name=txtMACAddr>

<INPUT value=58.245.184.191 name=txtIPAddr >

<INPUT value=typ name=txtDNSName >

</FORM>

/**

* 获取本地IP地址

*/

function getLocalIPAddress()

{

var obj = null

var rslt = "127.0.0.1"

try

{

obj = new ActiveXObject("rcbdyctl.Setting")

if (!isNull(obj.GetIPAddress))

{

rslt = obj.GetIPAddress

}

obj = null

}

catch(e)

{

//异常发生

}

return rslt

}