Internet explorer grab internal ip address

徘徊边缘 提交于 2021-02-16 20:07:33

问题


I'm looking for a solution to grab people's internal ip addresses in IE (not using java or java applets). The equivalent in Java looks like that:

this.sock.bind(new java.net.InetSocketAddress('0.0.0.0', 0));
this.sock.connect(new java.net.InetSocketAddress(document.domain, (!document.location.port)?80:document.location.port));
return this.sock.getLocalAddress().getHostAddress();

Is that something possible in vbscript or jscript? Could you provide me with an example?

Thanks for your time.


回答1:


You can not get internal IP with JavaScript.

This looks like something you'll need an ActiveX control for, if it is possible.




回答2:


I think that depending on the security settings in IE you might be able to use WMI. If so you could just use the Win32_NetworkAdapterConfiguration and it's IPAddress property.

The following sample in vbscript:

strComputer = "."
Set objWMIService = GetObject( _ 
    "winmgmts:\\" & strComputer & "\root\cimv2")
Set IPConfigSet = objWMIService.ExecQuery _
    ("Select IPAddress from Win32_NetworkAdapterConfiguration ")

For Each IPConfig in IPConfigSet
    If Not IsNull(IPConfig.IPAddress) Then 
        For i=LBound(IPConfig.IPAddress) _
            to UBound(IPConfig.IPAddress)
                WScript.Echo IPConfig.IPAddress(i)
        Next
    End If
Next

Is taken from this MSDN page.



来源:https://stackoverflow.com/questions/4241591/internet-explorer-grab-internal-ip-address

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!