Get the App
SLTechnology News&Howtos  ›  Development  › 

How to write the implementation code of .net Framework ping method

Shulou Source: shulou.com Published: 2022-06-02 11:39:29 09月22日 Update

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.

Tags: Methods code content skills knowledge space development simplicity brevity hosts people addresses benefits that is situations articles times more users articles Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information NVidia Xiaomi MariaDB OPPO Reno