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.
Asked
Active
Viewed 2,679 times
0
-
tried Google? here: http://msdn.microsoft.com/en-us/library/system.net.networkinformation.ping.aspx – mtijn Jan 23 '12 at 09:34
-
Why do you want to do that? Have you tried just opening a connection? – svick Jan 23 '12 at 09:35
-
1@mtijn, ping doesn't work with specific ports, just IP addresses. – svick Jan 23 '12 at 09:36
-
Telnet is what i use to check port specific stuff – undefined Jan 23 '12 at 09:36
-
use portquery to check post status. Ex: portqry -n ip address -e port number – Sai Kalyan Kumar Akshinthala Jan 23 '12 at 09:39
-
@svick: Im hosting a server and want to restart it when connection lost xd – Marcus Jan 23 '12 at 10:47
1 Answers
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