How to Ping an IP address in C#
By FoxLearn Published on May 15, 2024 10.1K
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 use sweetalert2
- How to Pass string parameter in an onclick function
- How to format number with commas and decimal in Javascript
- What does 'use strict;' means in Javascript
- How to detect if caps lock is pressed in Javascript
- How to create a Custom Event in Javascript
- How to Check if an Object Has a Property Properly in JavaScript
- How to convert an Uint8Array to string in Javascript
Categories
Popular Posts
11 Things You Didn't Know About Cloudflare
Dec 19, 2024
AdminKit Bootstrap 5 HTML5 UI Kits Template
Nov 17, 2024
RuangAdmin Template
Nov 13, 2024
Admin BSB Free Bootstrap Admin Dashboard
Nov 14, 2024