首页 > 开发 > 综合 > 正文

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

2024-07-21 02:09:57
字体:
来源:转载
供稿:网友


如何在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成功,反之失败
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表