Include these namespaces in your class:
The actual method to get the first open port from the system is as follows:
private string GetOpenPort()
int PortStartIndex = 1000;
int PortEndIndex = 2000;
IPGlobalProperties properties = IPGlobalProperties.GetIPGlobalProperties();
IPEndPoint tcpEndPoints = properties.GetActiveTcpListeners();
List<int> usedPorts = tcpEndPoints.Select(p => p.Port).ToList<int>();
int unusedPort = 0;
for (int port = PortStartIndex; port < PortEndIndex; port++)
unusedPort = port;
Software developer by profession, working for a service and product based organisation in India.
Software Programmer since 2002.
Web Developer in ASP.NET since 2004.
I love reading the blogs and articles of technology experts. I love codeproject and stackoverflow .
I love to share knowledge and help the programmers. I appreciate if some body corrects my code or my concepts which helps me learn.