VBS脚本如何获取当前计算机的ip地址?

2024-11-22 20:50:49
推荐回答(3个)
回答1:

如果你有Winsock控件的话,可以用下面的程序来得到:
Dim WS
Set WS=CreateObject("MSWinsock.Winsock")
MsgBox "Local IP=" & WS.LocalIP
弹出信息框中会显示本地IP。
而Winsock控件,可从通过安装VB6.0来获得。
///
代码如下
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set IPConfigSet = objWMIService.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

回答2:

如果你有Winsock控件的话,可以用下面的程序来得到:
Dim WS
Set WS=CreateObject("MSWinsock.Winsock")
MsgBox "Local IP=" & WS.LocalIP
弹出信息框中会显示本地IP。
而Winsock控件,可从通过安装VB6.0来获得。

回答3:

返回安装在计算机中的每个支持 IP 的网络适配器的 IP 地址。
脚本代码
strComputer = "."
Set objWMIService = GetObject("winmgmts:\" & strComputer & " ootcimv2")
Set IPConfigSet = objWMIService.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