0

I need to know how to check if an IP with Port is working to connect to. Port is 7171, and I'm using Visual Studio C# Express 2010 .NET.

Yahia
  • 69,653
  • 9
  • 115
  • 144
Marcus
  • 441
  • 3
  • 15
  • 27

1 Answers1

4

To check ip is working you can do a ping using your code and opening cmd from your code.

You can check if port is free assuming you are using tcpclint :

int port = 456; //<--- This is your value
bool isAvailable = true;

IPGlobalProperties ipGlobalProperties = IPGlobalProperties.GetIPGlobalProperties();
 TcpConnectionInformation[] tcpConnInfoArray = ipGlobalProperties.GetActiveTcpConnections();

 foreach (TcpConnectionInformation tcpi in tcpConnInfoArray)
 {
   if (tcpi.LocalEndPoint.Port==port)
   {
     isAvailable = false;
     break;
   }
 }
Zaki
  • 5,540
  • 7
  • 54
  • 91