在VB中如何使用ping命令。
With Visual Basic applications expanding more into the enterprise, basic networking functionality often needs to be duplicated by the application. Using the routine here, you will be able to ping any IP address passed.
Ping is a tool that helps to verify IP-level connectivity. When troubleshooting, the ping command is used to send an ICMP echo request to a target host name or IP address. Use ping whenever you need to verify that a host computer can connect to the TCP/IP network and network resources. You can also use the ping utility to isolate network hardware problems and incompatible configurations.
It is usually best to verify that a route exists between the local computer and a network host by first using ping and the IP address of the network host to which you want to connect. First try pinging the IP address of the target host to see if it will respond, because this is the simplest case.
The concept in the VB implementation is to pass to a routine the address to ping, and a message under 32 bytes that the ping should return if successful. This routine does not worked with named domains; it only works when passed the numerical address itself.
To test this application, you must be connected to a network or to your ISP via dial up networking (DUN).
I do not profess to know anything at all about networking or internet functions ... this code (as a bas file only) was provided to me unsigned. If the author is known, I注释:d appreciate hearing from them so proper credit can be given. Furthermore, it is commented only as far as the author did, with a bit of MSDN descriptions thrown in.
Finally, just to keep the error message lines short (narrow), I注释:ve split them into multiple lines as needed.
BAS Module Code
Add the following code to a BAS module:
--------------------------------------------------------------------------------
Option Explicit
注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:
注释: Copyright ?996-2000 VBnet, Randy Birch, All Rights Reserved.
注释: Some pages may also contain other copyrights by the author.
注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:
注释: You are free to use this code within your own applications,
注释: but you are expressly forbidden from selling or otherwise
注释: distributing this source code without prior written consent.
注释: This includes both posting free demo projects made from this
注释: code as well as reproducing the code in text or html format.
注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:
** Const IP_SUCCESS As Long = 0
** Const IP_STATUS_BASE As Long = 11000
** Const IP_BUF_TOO_SMALL As Long = (11000 1)
** Const IP_DEST_NET_UNREACHABLE As Long = (11000 2)
** Const IP_DEST_HOST_UNREACHABLE As Long = (11000 3)
** Const IP_DEST_PROT_UNREACHABLE As Long = (11000 4)
** Const IP_DEST_PORT_UNREACHABLE As Long = (11000 5)
** Const IP_NO_RESOURCES As Long = (11000 6)
** Const IP_BAD_OPTION As Long = (11000 7)
** Const IP_HW_ERROR As Long = (11000 8)
** Const IP_PACKET_TOO_BIG As Long = (11000 9)
** Const IP_REQ_TIMED_OUT As Long = (11000 10)
** Const IP_BAD_REQ As Long = (11000 11)
** Const IP_BAD_ROUTE As Long = (11000 12)
** Const IP_TTL_EXPIRED_TRANSIT As Long = (11000 13)
** Const IP_TTL_EXPIRED_REASSEM As Long = (11000 14)
** Const IP_PARAM_PROBLEM As Long = (11000 15)
** Const IP_SOURCE_QUENCH As Long = (11000 16)
** Const IP_OPTION_TOO_BIG As Long = (11000 17)
** Const IP_BAD_DESTINATION As Long = (11000 18)
** Const IP_ADDR_DELETED As Long = (11000 19)
** Const IP_SPEC_MTU_CHANGE As Long = (11000 20)
** Const IP_MTU_CHANGE As Long = (11000 21)
** Const IP_UNLOAD As Long = (11000 22)
** Const IP_ADDR_ADDED As Long = (11000 23)
** Const IP_GENERAL_FAILURE As Long = (11000 50)
** Const MAX_IP_STATUS As Long = (11000 50)
** Const IP_PENDING As Long = (11000 255)
** Const PING_TIMEOUT As Long = 500
** Const WS_VERSION_REQD As Long =
搜索更多相关主题的帖子:
ping 命令