|
'本地IP
Sub test()
Dim Ip$, strComputer$
Dim objwmiservice As Object, ipconfigset As Object
strComputer = "."
Set objwmiservice = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set ipconfigset = objwmiservice.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration ")
For Each IPConfig In ipconfigset
On Error Resume Next
Ip = IPConfig.IPAddress(0) & ""
Next
MsgBox Ip
End Sub
'外网IP
Sub GetOutIP()
Dim xmlhttp As Object
Dim strURL As String, strTemp As String
strURL = "http://www.ip138.com/ip2city.asp"
Set xmlhttp = CreateObject("Microsoft.XMLHTTP")
xmlhttp.Open "GET", strURL, False
xmlhttp.send
If xmlhttp.Status = 200 Then
strTemp = xmlhttp.responsetext
strTemp = Mid(strTemp, InStr(1, strTemp, "[") + 1)
strTemp = Left(strTemp, InStr(1, strTemp, "]") - 1)
MsgBox "外网IP地址: " & strTemp
Else
MsgBox xmlhttp.Status & vbCrLf & xmlhttp.StatusText
End If
End Sub |
|