 <p>Since you're using a <code>TcpClient</code>, that means you're checking open TCP ports. There are lots of good objects available in the <a href="http://msdn.microsoft.com/en-us/library/system.net.networkinformation.aspx" rel="nofollow noreferrer">System.Net.NetworkInformation</a> namespace.</p> <p>Use the <code>IPGlobalProperties</code> object to get to an array of <code>TcpConnectionInformation</code> objects, which you can then interrogate about endpoint IP and port.</p> <hr> <pre><code> int port = 456; //&lt;--- This is your value bool isAvailable = true; // Evaluate current system tcp connections. This is the same information provided // by the netstat command line application, just in .Net strongly-typed object // form. We will look through the list, and if our port we would like to use // in our TcpClient is occupied, we will set isAvailable to false. IPGlobalProperties ipGlobalProperties = IPGlobalProperties.GetIPGlobalProperties(); TcpConnectionInformation[] tcpConnInfoArray = ipGlobalProperties.GetActiveTcpConnections(); foreach (TcpConnectionInformation tcpi in tcpConnInfoArray) { if (tcpi.LocalEndPoint.Port==port) { isAvailable = false; break; } } // At this point, if isAvailable is true, we can proceed accordingly. </code></pre>