Skip to content

Instantly share code, notes, and snippets.

@AlexArchive
Created June 17, 2013 20:20
Show Gist options
  • Save AlexArchive/5799995 to your computer and use it in GitHub Desktop.
Save AlexArchive/5799995 to your computer and use it in GitHub Desktop.
Check if a TCP port is available / already in use on local machine
private static bool PortAvailableForListening(int portNumber)
{
IPEndPoint[] activeTcpListeners = IPGlobalProperties.GetIPGlobalProperties().GetActiveTcpListeners();
return activeTcpListeners.Select(x => x.Port == portNumber).FirstOrDefault();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment