如何在PB中编写PING代码?(改编)

类别:数据库 点击:0 评论:0 推荐:

如何在PB中编写PING代码?

问题描述:

如何在PB中编写PING代码?

解决方案:

声明外部函数:

 

Function ulong IcmpCreateFile () Library "icmp.dll"

Function long IcmpSendEcho (ulong IcmpHandle, ulong DestinationAddress, string RequestData,long RequestSize, long RequestOptions, Ref icmp_echo_reply ReplyBuffer, long ReplySize, long Timeout ) Library "icmp.dll" Alias for "IcmpSendEcho"

Function long IcmpCloseHandle (ulong IcmpHandle) Library "icmp.dll"

Function ulong inet_addr (string cp) Library "ws2_32.dll" Alias for "inet_addr"

 

代码:

 

ULong lul_address, lul_handle

Long ll_rc, ll_size

String ls_reply

icmp_echo_reply lstr_reply

 

lul_address = inet_addr(as_ipaddress)

If lul_address > 0 Then

lul_handle = IcmpCreateFile()

ll_size = Len(as_echomsg)

ll_rc = IcmpSendEcho(lul_handle, lul_address, &

as_echomsg, ll_size, 0, &

lstr_reply, 278, 200)

IcmpCloseHandle(lul_handle)

If ll_rc <> 0 Then

If lstr_reply.Status = 0 Then

ls_reply = String(lstr_reply.Data)

If ls_reply = as_echomsg Then

Return True

End If

End If

End If

End If

 

Return False

 

//True 表示PING成功,反之失败

本文地址:http://com.8s8s.com/it/it19515.htm