VB下能够ping某个IP判断网络是否连接通
若以下回答无法解决问题,邀请你更新回答
展开全部
Public Const WS_VERSION_REQD As Long = &H101
Public Const INADDR_NONE As Long = &HFFFFFFFF
Public Const MAX_WSADescription As Long = 256
Public Const MAX_WSASYSStatus As Long = 128
Public Const PING_TIMEOUT As Long = 500
Public Type ICMP_OPTIONS
Ttl As Byte
Tos As Byte
Flags As Byte
OptionsSize As Byte
OptionsData As Long
End Type
Public Type ICMP_ECHO_REPLY
Address As Long
status As Long
RoundTripTime As Long
DataSize As Long
Reserved As Integer
DataPointer As Long
Options As ICMP_OPTIONS
Data As String * 250
End Type
Public Type WSADATA
wVersion As Integer
wHighVersion As Integer
szDescription(0 To MAX_WSADescription) As Byte
szSystemStatus(0 To MAX_WSASYSStatus) As Byte
wMaxSockets As Long
wMaxUDPDG As Long
dwVendorInfo As Long
End Type
Public Declare Function IcmpCreateFile Lib "icmp.dll" () As Long
Public Declare Function IcmpCloseHandle Lib "icmp.dll" (ByVal IcmpHandle As Long) As Long
Public Declare Function IcmpSendEcho Lib "icmp.dll" (ByVal IcmpHandle As Long, _
ByVal DestinationAddress As Long, ByVal RequestData As String, ByVal RequestSize As Long, _
ByVal RequestOptions As Long, ReplyBuffer As ICMP_ECHO_REPLY, ByVal ReplySize As Long, _
ByVal Timeout As Long) As Long
Public Declare Function WSAStartup Lib "WSOCK32.DLL" (ByVal wVersionRequired As Long, _
lpWSADATA As WSADATA) As Long
Public Declare Function WSACleanup Lib "WSOCK32.DLL" () As Long
Public Declare Function gethostname Lib "WSOCK32.DLL" (ByVal szHost As String, _
ByVal dwHostLen As Long) As Long
Public Declare Function gethostbyname Lib "WSOCK32.DLL" (ByVal szHost As String) As Long
Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
(xDest As Any, xSource As Any, ByVal nbytes As Long)
Public Declare Function inet_addr Lib "WSOCK32.DLL" (ByVal s As String) As Long
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Public Function LongToIP(Address As Long) As String
'344203530→ 10.33.132.20
If Address > 16777216 Then
Dim s As String
s = ""
s = CStr(Address Mod 256) & "."
s = s & CStr((Address \ 256) Mod 256) & "."
s = s & CStr((Address \ 65536) Mod 256) & "."
s = s & CStr(Address \ 16777216)
LongToIP = s
Else
LongToIP = "值范围过小,请检查!"
End If
End Function
Public Function IsIP(ByVal IpAddress As String) As Boolean
IsIP = False
If IpAddress = "" Then
Exit Function
End If
Dim s() As String
s = Split(IpAddress, ".")
If UBound(s) = 3 Then
If Val(s(0)) >= 1 And Val(s(0)) < 255 And Val(s(1)) >= 0 And Val(s(1)) <= 255 And Val(s(2)) >= 0 And Val(s(2)) <= 255 And Val(s(3)) >= 1 And Val(s(3)) <= 255 Then
IsIP = True
End If
End If
End Function
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询