当前位置:开发者网络 >> 技术教程 >> 数据库专栏 >> 其他相关 >> 内容
精彩推荐
分类最新教程
分类热点教程
  
如何在PB中编写PING代码?(改编)
作者:未知
日期:2005-04-29
人气:
投稿:(转贴)
来源:未知
字体:
收藏:加入浏览器收藏
以下正文:

如何在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成功,反之失败
相关文章: