Windows Forms: Ping an IP address in C#

This post shows you How to Ping an IP address using C# .NET Windows Forms Application.

Dragging Label, TextBox and Button controls from the Visual Studio Toolbox to your form designer.

ping an ip address using c#

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);

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.