手机站
网通分站
电信主站
密 码:
用户名:
当前位置 : 主页>程序设计>delphi>列表

我写了个 Ping 模块 很实用!

来源:互联网 作者:西部数码 时间:2008-04-10
西部数码-全国虚拟主机10强!40余项虚拟主机管理功能,全国领先!双线多线虚拟主机南北访问畅通无阻!免费赠送企业邮局,.CN域名,自助建站480元起,免费试用7天,满意再付款! P4主机租用799元/月.月付免压金!

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
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!