[分享]纯VB实现ping(能否ping通)的功能,调用方便
'调用:msgbox IPValid("192.168.1.1")
'模块代码,以下代码统一放入一个模块中mPing'互联网搜索得到,略加整理Private Const IP_STATUS_BASE = 11000Private Const IP_SUCCESS = 0Private Const IP_BUF_TOO_SMALL = (11000 + 1)Private Const IP_DEST_NET_UNREACHABLE = (11000 + 2)Private Const IP_DEST_HOST_UNREACHABLE = (11000 + 3)Private Const IP_DEST_PROT_UNREACHABLE = (11000 + 4)Private Const IP_DEST_PORT_UNREACHABLE = (11000 + 5)Private Const IP_NO_RESOURCES = (11000 + 6)Private Const IP_BAD_OPTION = (11000 + 7)Private Const IP_HW_ERROR = (11000 + 8)Private Const IP_PACKET_TOO_BIG = (11000 + 9)Private Const IP_REQ_TIMED_OUT = (11000 + 10)Private Const IP_BAD_REQ = (11000 + 11)Private Const IP_BAD_ROUTE = (11000 + 12)Private Const IP_TTL_EXPIRED_TRANSIT = (11000 + 13)Private Const IP_TTL_EXPIRED_REASSEM = (11000 + 14)Private Const IP_PARAM_PROBLEM = (11000 + 15)Private Const IP_SOURCE_QUENCH = (11000 + 16)Private Const IP_OPTION_TOO_BIG = (11000 + 17)Private Const IP_BAD_DESTINATION = (11000 + 18)Private Const IP_ADDR_DELETED = (11000 + 19)Private Const IP_SPEC_MTU_CHANGE = (11000 + 20)Private Const IP_MTU_CHANGE = (11000 + 21)Private Const IP_UNLOAD = (11000 + 22)Private Const IP_ADDR_ADDED = (11000 + 23)Private Const IP_GENERAL_FAILURE = (11000 + 50)Private Const MAX_IP_STATUS = 11000 + 50Private Const IP_PENDING = (11000 + 255)Private Const PING_TIMEOUT = 200Private Const WS_VERSION_REQD = &H101Private Const WS_VERSION_MAJOR = WS_VERSION_REQD \ &H100 And &HFF&Private Const WS_VERSION_MINOR = WS_VERSION_REQD And &HFF&Private Const MIN_SOCKETS_REQD = 1Private Const SOCKET_ERROR = -1Private Const MAX_WSADescription = 256Private Const MAX_WSASYSStatus = 128Private Type ICMP_OPTIONS Ttl As Byte Tos As Byte Flags As Byte OptionsSize As Byte OptionsData As LongEnd TypeDim ICMPOPT As ICMP_OPTIONSPrivate Type ICMP_ECHO_REPLY Address As Long status As Long RoundTripTime As Long DataSize As Integer Reserved As Integer DataPointer As Long Options As ICMP_OPTIONS Data As String * 250End TypePrivate Type WSADATA wVersion As Integer wHighVersion As Integer szDescription(0 To MAX_WSADescription) As Byte szSystemStatus(0 To MAX_WSASYSStatus) As Byte wMaxSockets As Integer wMaxUDPDG As Integer dwVendorInfo As LongEnd TypePrivate Declare Function IcmpCreateFile Lib "icmp.dll" () As LongPrivate Declare Function IcmpCloseHandle Lib "icmp.dll" _ (ByVal IcmpHandle As Long) _ As Long Private Declare Function IcmpSendEcho Lib "icmp.dll" _ (ByVal IcmpHandle As Long, _ ByVal DestinationAddress As Long, _ ByVal RequestData As String, _ ByVal RequestSize As Integer, _ ByVal RequestOptions As Long, _ ReplyBuffer As ICMP_ECHO_REPLY, _ ByVal ReplySize As Long, _ ByVal Timeout As Long) _ As Long Private Declare Function WSAGetLastError Lib "WSOCK32.DLL" () As LongPrivate Declare Function WSAStartup Lib "WSOCK32.DLL" _ (ByVal wVersionRequired As Long, _ lpWSADATA As WSADATA) _ As Long Private Declare Function WSACleanup Lib "WSOCK32.DLL" () As Long