如何获得本机的IP地址?
通过下面的代码可以获得IP地址:
Dim WS
Set WS = CreateObject("MSWinsock.Winsock")
IPAddress = WS.LocalIP
MsgBox "Local IP = " & IPAddress
下面是利用WMI进行同样的工作,虽然比较麻烦,但也是一种方法:
set IPConfigSet =
GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery _
("select IPAddress from
Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
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
|