欢迎光临
我们一直在努力

ping一个ip地址(向它发送一个数据包并等待回应))_visualbasic教程

建站超值云服务器,限时71元/月

本例演示了怎样通过API的调用向一个IP地址发送一个包的数据并等待回音。
新建一个工程,添加一个标准模块,写入以下代码:

OptionExplicit

PublicConstIP_STATUS_BASE=11000
PublicConstIP_SUCCESS=0
PublicConstIP_BUF_TOO_SMALL=(11000 1)
PublicConstIP_DEST_NET_UNREACHABLE=(11000 2)
PublicConstIP_DEST_HOST_UNREACHABLE=(11000 3)
PublicConstIP_DEST_PROT_UNREACHABLE=(11000 4)
PublicConstIP_DEST_PORT_UNREACHABLE=(11000 5)
PublicConstIP_NO_RESOURCES=(11000 6)
PublicConstIP_BAD_OPTION=(11000 7)
PublicConstIP_HW_ERROR=(11000 8)
PublicConstIP_PACKET_TOO_BIG=(11000 9)
PublicConstIP_REQ_TIMED_OUT=(11000 10)
PublicConstIP_BAD_REQ=(11000 11)
PublicConstIP_BAD_ROUTE=(11000 12)
PublicConstIP_TTL_EXPIRED_TRANSIT=(11000 13)
PublicConstIP_TTL_EXPIRED_REASSEM=(11000 14)
PublicConstIP_PARAM_PROBLEM=(11000 15)
PublicConstIP_SOURCE_QUENCH=(11000 16)
PublicConstIP_OPTION_TOO_BIG=(11000 17)
PublicConstIP_BAD_DESTINATION=(11000 18)
PublicConstIP_ADDR_DELETED=(11000 19)
PublicConstIP_SPEC_MTU_CHANGE=(11000 20)
PublicConstIP_MTU_CHANGE=(11000 21)
PublicConstIP_UNLOAD=(11000 22)
PublicConstIP_ADDR_ADDED=(11000 23)
PublicConstIP_GENERAL_FAILURE=(11000 50)
PublicConstMAX_IP_STATUS=11000 50
PublicConstIP_PENDING=(11000 255)
PublicConstPING_TIMEOUT=200
PublicConstWS_VERSION_REQD=&H101
PublicConstWS_VERSION_MAJOR=WS_VERSION_REQD\&H100And&HFF&
PublicConstWS_VERSION_MINOR=WS_VERSION_REQDAnd&HFF&
PublicConstMIN_SOCKETS_REQD=1
PublicConstSOCKET_ERROR=-1

PublicConstMAX_WSADescription=256
PublicConstMAX_WSASYSStatus=128

PublicTypeICMP_OPTIONS
TtlAsByte
TosAsByte
FlagsAsByte
OptionsSizeAsByte
OptionsDataAsLong
EndType

DimICMPOPTAsICMP_OPTIONS

PublicTypeICMP_ECHO_REPLY
AddressAsLong
statusAsLong
RoundTripTimeAsLong
DataSizeAsInteger
ReservedAsInteger
DataPointerAsLong
OptionsAsICMP_OPTIONS
DataAsString*250
EndType

PublicTypeHOSTENT
hNameAsLong
hAliasesAsLong
hAddrTypeAsInteger
hLenAsInteger
hAddrListAsLong
EndType

PublicTypeWSADATA
wVersionAsInteger
wHighVersionAsInteger
szDescription(0ToMAX_WSADescription)AsByte
szSystemStatus(0ToMAX_WSASYSStatus)AsByte
wMaxSocketsAsInteger
wMaxUDPDGAsInteger
dwVendorInfoAsLong
EndType

PublicDeclareFunctionIcmpCreateFileLib”icmp.dll”()AsLong
PublicDeclareFunctionIcmpCloseHandleLib”icmp.dll”(ByValIcmpHandleAsLong)AsLong
PublicDeclareFunctionIcmpSendEchoLib”icmp.dll”(ByValIcmpHandleAsLong,ByValDestinationAddressAsLong,ByValRequestDataAsString,ByValRequestSizeAsInteger,ByValRequestOptionsAsLong,ReplyBufferAsICMP_ECHO_REPLY,ByValReplySizeAsLong,ByValTimeoutAsLong)AsLong
PublicDeclareFunctionWSAGetLastErrorLib”WSOCK32.DLL”()AsLong
PublicDeclareFunctionWSAStartupLib”WSOCK32.DLL”(ByValwVersionRequiredAsLong,lpWSADATAAsWSADATA)AsLong
PublicDeclareFunctionWSACleanupLib”WSOCK32.DLL”()AsLong
PublicDeclareFunctiongethostnameLib”WSOCK32.DLL”(ByValszHostAsString,ByValdwHostLenAsLong)AsLong
PublicDeclareFunctiongethostbynameLib”WSOCK32.DLL”(ByValszHostAsString)AsLong
PublicDeclareSubRtlMoveMemoryLib”kernel32″(hpvDestAsAny,ByValhpvSourceAsLong,ByValcbCopyAsLong)

PublicFunctionGetStatusCode(statusAsLong)AsString

DimmsgAsString

SelectCasestatus
CaseIP_SUCCESS:msg=”ipsuccess”
CaseIP_BUF_TOO_SMALL:msg=”ipbuftoo_small”
CaseIP_DEST_NET_UNREACHABLE:msg=”ipdestnetunreachable”
CaseIP_DEST_HOST_UNREACHABLE:msg=”ipdesthostunreachable”
CaseIP_DEST_PROT_UNREACHABLE:msg=”ipdestprotunreachable”
CaseIP_DEST_PORT_UNREACHABLE:msg=”ipdestportunreachable”
CaseIP_NO_RESOURCES:msg=”ipnoresources”
CaseIP_BAD_OPTION:msg=”ipbadoption”
CaseIP_HW_ERROR:msg=”iphw_error”
CaseIP_PACKET_TOO_BIG:msg=”ippackettoo_big”
CaseIP_REQ_TIMED_OUT:msg=”ipreqtimedout”
CaseIP_BAD_REQ:msg=”ipbadreq”
CaseIP_BAD_ROUTE:msg=”ipbadroute”
CaseIP_TTL_EXPIRED_TRANSIT:msg=”ipttlexpiredtransit”
CaseIP_TTL_EXPIRED_REASSEM:msg=”ipttlexpiredreassem”
CaseIP_PARAM_PROBLEM:msg=”ipparam_problem”
CaseIP_SOURCE_QUENCH:msg=”ipsourcequench”
CaseIP_OPTION_TOO_BIG:msg=”ipoptiontoo_big”
CaseIP_BAD_DESTINATION:msg=”ipbaddestination”
CaseIP_ADDR_DELETED:msg=”ipaddrdeleted”
CaseIP_SPEC_MTU_CHANGE:msg=”ipspecmtuchange->

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » ping一个ip地址(向它发送一个数据包并等待回应))_visualbasic教程
分享到: 更多 (0)