请教一个IcmpCreateFile()的问题
......Private Function Ping(ByVal szAddress As String, ByVal ECHO As ICMP_ECHO_REPLY) As Long
Dim hPort As Long
Dim dwAddress As Long
Dim sDataToSend As String
Dim iOpt As Long
sDataToSend = "Echo This"
dwAddress = AddressStringToLong(szAddress)
hPort = IcmpCreateFile()
If IcmpSendEcho(hPort, _
dwAddress, _
sDataToSend, _
Len(sDataToSend), _
0, _
ECHO, _
Len(ECHO), _
PING_TIMEOUT) Then
'the ping succeeded,
'.Status will be 0
'.RoundTripTime is the time in ms for
' the ping to complete,
'.Data is the data returned (NULL terminated)
'.Address is the Ip address that actually replied
'.DataSize is the size of the string in .Data
Ping = ECHO.RoundTripTime
Else : Ping = ECHO.status * -1
End If
Call IcmpCloseHandle(hPort)
End Function
......
这段代码的是一段关于Ping()的程序里节选出来的,在Execl中的VBA运行正常,但是在VB.net中却运行异常,表现在对于同一个IP转换成dwAddress时,有时一致,有时不一致,最主要的差别是hPort = IcmpCreateFile()返回值不一致,
If IcmpSendEcho(hPort, _
dwAddress, _
sDataToSend, _
Len(sDataToSend), _
0, _
ECHO, _
Len(ECHO), _
PING_TIMEOUT) Then ......
总是返回True,IP和本机不在一个网段内。
请各位老师们帮着分析分析 --------------------编程问答-------------------- 楼上兄弟:
我也在做ping这个程序,你的 dwAddress = AddressStringToLong(szAddress) 是不是一个把ip的点分段变成一个long数据呢?
你把Public Declare Function inet_addr Lib "WSOCK32.DLL" (ByVal s As String) As Long 然后dwAddress = inet_addr(sAddress) 替换一下试试看...
补充:.NET技术 , VB.NET