Private Sub Command1_Click()
MsgBox GetIP(" www.csdn.net")
End Sub
Function GetIP(URL As String) As String
Shell "command.com /c ping " & URL & " -n 1 > c:/ping", vbHide
Dim fn As Integer
fn = FreeFile
RETRY:
Open "c:/ping" For Binary Access Read As #fn
GetIP = Space(FileLen("c:/ping"))
Get #fn, , GetIP
Close #fn
If Len(GetIP) = 0 Then GoTo RETRY
GetIP = Left$(GetIP, InStr(GetIP, "]") - 1)
GetIP = Mid$(GetIP, InStr(GetIP, "[") + 1)
Kill "c:/ping"
End Function
MsgBox GetIP(" www.csdn.net")
End Sub
Function GetIP(URL As String) As String
Shell "command.com /c ping " & URL & " -n 1 > c:/ping", vbHide
Dim fn As Integer
fn = FreeFile
RETRY:
Open "c:/ping" For Binary Access Read As #fn
GetIP = Space(FileLen("c:/ping"))
Get #fn, , GetIP
Close #fn
If Len(GetIP) = 0 Then GoTo RETRY
GetIP = Left$(GetIP, InStr(GetIP, "]") - 1)
GetIP = Mid$(GetIP, InStr(GetIP, "[") + 1)
Kill "c:/ping"
End Function