How to Ping an IP address in C#
By FoxLearn 7/18/2024 8:07:52 AM 9.37K
Pinging an IP address in a C# Windows Forms application can be accomplished using the Ping class from the System.Net.NetworkInformation namespace.
How to ping an IP address in C#
Drag and drop the Label, TextBox and Button controls from the Visual Studio toolbox to your form designer.
Adding a click event handler to the Ping button allows you to ping an ip address.
private void btnPing_Click(object sender, EventArgs e) { Ping ping = new Ping(); PingReply reply = ping.Send(txtIP.Text, 1000); MessageBox.Show(reply.Status.ToString(), "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); }
Enter an IP address or hostname in the txtIP
TextBox, then click the btnPing
Button. The result will be displayed in the MessageBox
.
And don't forget to include the namespace below to your form.
using System.Net.NetworkInformation;
The PING class determines whether a remote computer can be accessed over the network. It provides the same functionality as the PING.EXE command line tool.
- How to get datatype in JavaScript
- How to convert string to boolean in Javascript
- How to Zip file folder in C#
- How to fix 'Fetch request to https:www.google.com fails with CORS'
- How to Check Internet Connection Status in Javascript
- How to download file using JavaScript
- How to get selected option in JQuery
- How to get data attribute JavaScript
Categories
Popular Posts
Responsive Animated Login Form
11/11/2024
Carpatin Admin Dashboard Template
11/17/2024
Plus Admin Dashboard Template
11/18/2024