函数功能:获取本机所有IP地址,并用空格连接后返回,后期可通过split函数分割
Function GetAllIP()
GetAllIP = ""
Dim objWMIService, colAdapters, objAdapter,strComputer
Dim a,i
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colAdapters = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
If colAdapters.Count = 0 Then
Exit Function
End If
If Ubound(colAdapters.ItemIndex(0).IPAddress) = 0 Then
Exit Function
End If
'colAdapters.count=3时,msgbox ubound(colAdapters.ItemIndex(3).IPAddress),需为ItemIndex(2),否则报错
a = colAdapters.Count'colAdapters.Count数量
for a = 0 to a -1 'ItemIndex 索引从0计数
for i = 0 to Ubound(colAdapters.ItemIndex(a).IPAddress)
GetAllIP = GetAllIP & " " & colAdapters.ItemIndex(a).IPAddress(i)
next
next
End Function
SecureCRT VBS脚本之获取本机所有IP地址
于 2023-11-30 09:40:27 首次发布