How to write the implementation code of .net Framework ping method
This article shows you how to write the implementation code of the .Net Framework ping method, the content is concise and easy to understand, it will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.
Developers will be deeply aware of the benefits when using .net Framework for development. .net Framework2.0 provides the System.Net.NetWorkInformation namespace, and we can use the ping class under this namespace to easily implement the .net Framework ping method.
The following is the code implemented by the .net Framework ping method:
Using System
Using System.Collections.Generic
Using System.Text
Using System.Net
Using System.Net.NetworkInformation
Namespace PingDotNET
{
Class Program
{
Static void Main (string [] args)
{
/ / display details
Console.WriteLine ("Ping in.
NET Framework 2.0 ")
Console.WriteLine ("use .NET"
Written by Framework 2.0 ")
/ / Let the user enter the hostname to get the ip address of ping
If (args.Length = = 0)
{
Console.WriteLine ("Usage: PingDotNET")
Return
}
/ / initialize the ping class
Ping refPing = new Ping ()
PingReply refPingResult = null
/ / call the send method of ping
Console.WriteLine ("Pinging {0})
", args [0])
RefPingrefPingResult = refPing.
Send (args [0])
Console.WriteLine ("Ping Status: {0}"
RefPingResult.Status.ToString ()
Console.WriteLine ("RoundTrip Time"
[millisec]: {0} ", refPingResult.
RoundTripTime)
If (refPingResult.Options! = null)
Console.WriteLine ("TTL: {0}"
RefPingResult.Options.Ttl.ToString ()
}
}
}
The above is how to write the code for the implementation of the .net Framework ping method. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.