Tech Talk A software developer on all things tech, and then some

15May/120

Checking Status of IP with Port Number in C#

Ever need to check the status of a server, but through a port as well? I needed to as well recently, and came up with a quick, clean method to check the status of a server address and port. This will return a boolean, giving the status of whether the server is running and port is open.

public static bool PingHost(string _HostURI, int _PortNumber)
{
	try
	{
		TcpClient client = new TcpClient(_HostURI, _PortNumber);
		return true;
	}
	catch (Exception ex)
	{
		MessageBox.Show("Error pinging host:'" + _HostURI + ":" + _PortNumber.ToString() + "'");
		return false;
	}
}

Hope this helps and happy coding!

Comments (0) Trackbacks (0)

No comments yet.


Leave a Reply

No trackbacks yet.

%d bloggers like this: