Case IP_NO_RESOURCES: Msg = "ip no resources"
Case IP_BAD_OPTION: Msg = "ip bad option"
Case IP_HW_ERROR: Msg = "ip hw_error"
Case IP_PACKET_TOO_BIG: Msg = "ip packet too_big"
Case IP_REQ_TIMED_OUT: Msg = "ip req timed out"
Case IP_BAD_REQ: Msg = "ip bad req"
Case IP_BAD_ROUTE: Msg = "ip bad route"
Case IP_TTL_EXPIRED_TRANSIT: Msg = "ip ttl expired transit"
Case IP_TTL_EXPIRED_REASSEM: Msg = "ip ttl expired reassem"
Case IP_PARAM_PROBLEM: Msg = "ip param_problem"
Case IP_SOURCE_QUENCH: Msg = "ip source quench"
Case IP_OPTION_TOO_BIG: Msg = "ip option too_big"
Case IP_BAD_DESTINATION: Msg = "ip bad destination"
Case IP_ADDR_DELETED: Msg = "ip addr deleted"
Case IP_SPEC_MTU_CHANGE: Msg = "ip spec mtu change"
Case IP_MTU_CHANGE: Msg = "ip mtu_change"
Case IP_UNLOAD: Msg = "ip unload"
Case IP_ADDR_ADDED: Msg = "ip addr added"
Case IP_GENERAL_FAILURE: Msg = "ip general failure"
Case IP_PENDING: Msg = "ip pending"
Case PING_TIMEOUT: Msg = "ping timeout"
Case Else: Msg = "unknown msg returned"
End Select
GetStatusCode = Msg
Exit Function
Z:
GetStatusCode = ""
End Function
Private Function Ping(sAddress As String, sDataToSend As String, ECHO As ICMP_ECHO_REPLY) As Long
On Error GoTo Z
Dim hPort As Long
Dim dwAddress As Long
dwAddress = inet_addr(sAddress)
If dwAddress <> INADDR_NONE Then
hPort = IcmpCreateFile()
If hPort Then
Call IcmpSendEcho(hPort, dwAddress, sDataToSend, Len(sDataToSend), 0, ECHO, Len(ECHO), PING_TIMEOUT)
Ping = ECHO.status
Call IcmpCloseHandle(hPort)
End If
Else
Ping = INADDR_NONE
End If
Exit Function
Z:
Ping = INADDR_NONE
End Function
''''(Ping函数)
'''' 参数:目标IP地址
''''返回值:存在返回True,否则返回False
Public Function PingIp(ByVal szIp As String) As Boolean
On Error GoTo Z
Dim WSAD As WSADATA
Dim ECHO As ICMP_ECHO_REPLY
Dim ret As Long
If WSAStartup(WS_VERSION_REQD, WSAD) = IP_SUCCESS Then
ret = Ping(Trim(szIp), "tanaya", ECHO)
If InStr(1, GetStatusCode(ret), "success") <> 0 Then
WSACleanup
PingIp = True
Exit Function
End If
End If
PingIp = False
Exit Function
Z:
PingIp = False
End Function
会Delphi的朋友可以把这个模块移植,很简单,不敲键盘了.
''''-------------------------------------------
'''' 转载请注明出处
'''' 作者:唐细刚
'''' 邮箱:tanaya@163.com
''''-------------------------------------------
文章整理:西部数码--专业提供域名注册、虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!




