vba 获取本机ip

Sub GetMyIP()
Dim strComputer As String
Dim objWMI As Object
Dim colIP As Object
Dim IP As Object
Dim i As Integer

strComputer = "."
Set objWMI = GetObject("winmgmts://" & strComputer & "/root/cimv2")
Set colIP = objWMI.ExecQuery _
    ("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
For Each IP In colIP
    If Not IsNull(IP.IPAddress) Then
        For i = LBound(IP.IPAddress) To UBound(IP.IPAddress)
        MsgBox IP.IPAddress(i), vbInformation, IP.Description(i)
    Next
    End If
Next

End Sub

你可能感兴趣的:(each,VBA)