the namespace System.Net.Networklnformation provides specific classes of network traffic data, network address information, and the ability to detect whether or not the network allows access.
Ping class
The Ping class provides the functionality required to detect network presence, which must match several other classes in order to obtain relevant data, such as:
Ipstatus defines the status code, which describes the results of the ICMP echo request message;
pingoptions set or get: The number of packets transmitted (TTL), and whether the packet can be dispersed dontfragment);
The pingreply contains the results of the ICMP echo request, and the Pingreply object encapsulates the results returned by the network during the ping operation.
Pingexception thrown when an irreversible error occurs (the exception class for the related operation).
Basic Knowledge
--------------------
ICMP
is (Internet Control message Protocol) Internet Controlled message protocol. It is a sub-protocol of the TCP/IP protocol family that is used to pass control messages between IP hosts and routers. The control message refers to the message that the network is not accessible, whether the host is available, whether the route is available, and so on. These control messages, while not transmitting user data, play an important role in the delivery of user data.
The ICMP protocol is a non-connection-oriented protocol for transmitting error reporting control information. It is a very important protocol, it is very important for network security. From a technical point of view, ICMP is a "false detection and reward mechanism", which is designed to enable us to detect the connection status of the network and to ensure the accuracy of the connection.
---------------------
RTT
(round-trip time): round trip delay. Indicates that the data is sent from the sending side to the sender to receive the acknowledgement from the receiving end (the receiving side receives the data and sends an acknowledgement immediately), the total experience of the delay.
The round-trip delay (RTT) is determined by three parts: the propagation time of the link, the processing time of the end system, and the queuing and processing time in the router's cache.
The values in the previous two parts are relatively fixed as a TCP connection, and the queuing and processing time in the router's cache varies with the overall network congestion level.
Therefore, the change of RTT reflects the change of network congestion degree to some extent.
-------------------
TTL
is the abbreviation for time to live, which specifies the maximum number of network segments that an IP packet is allowed to pass before it is discarded by the router. The TTL is a 8 bit field in the IPV4 header, which is located in the 9th byte of the IPV4 packet.
the function of TTL is to limit the time that IP packets exist in the computer network. The maximum TTL value is one of the recommended values for 255,ttl is 64.
The main function of TTL is to avoid the infinite loop and send and receive of IP packets in the network, save the network resources, and enable the sender of IP packets to receive the alarm message.
-------------------
the method of ping class send ()
sends an ICMP response message to a specific network, with an IP or hostname, resulting in an ICMP reply message returned and encapsulated in the Pingreply object:
Public function send (address as IPAddress) as Pingreply public function Send (hostnameoraddress as String) as Pingr Eply
Cases:
Dim myping as New Ping ()
Dim prreply as pingreply = Myping.send ("192.168.1.3")
Second, pingreply object
it cannot be created directly, but only through the Send () method. Several of its properties are more important:
address obtains the returned IP;
the size of the data buffer received by buffer when the ICMP response reply was obtained (byte array);
options access option, the content of the ICMP reply message;
Status gets a different ICMP response message state.
1. Options
is the content of the ICMP reply message, which returns a PingOptions class object:
Public Readonly Property Options as PingOptions
PingOptions set or get: Packet forwarding (TTL), whether the packet can be dispersed (dontfragment):
reply. OPTIONS.TT1
reply. Options.dontfragment
(reply for pingreply objects)
Span style= "Background-color:rgb (255,255,153)" > 2, Status
is a Ipstatus enumeration class that defines a large number of enumeration values that represent different ICMP response message states.
It contains success for successful response and various reasons for failure, such as timedout, time-to-live (TTL), which did not receive the ICMP response within the specified time, has reached 0. Causes the forwarding node (router or gateway) to discard packets of timeexceeded, and so on.
&N Bsp
Imports System.Net.NetworkInformationPublic Class Form1 Private Sub btnip_click (sender as Object, e as EventArgs) Han DLEs Btnip.click Dim myIP As New Ping Dim prreply As Pingreply = Myip.send (txtip.text) txtinfo.text = "IP address:
"& prReply.Address.ToString & vbCrLf & " buffer size: "& prReply.Buffer.Length & vbCrLf & " Round-Trip delay: "& Prreply.roundtriptime & vbCrLf & " Time to Live: "& PrReply.Options.Ttl & vbCrLf & " Success/Failure Status: "& prReply.Status.ToString End subend Class
Notes 8:ping Class