Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check remote IP and Port is available?

I have to check remote IP and Port is available or not.If its is available it will move to next form.If not available it should come to the initial state.I tried using this

while (true)
{
    IPGlobalProperties ipProperties = IPGlobalProperties.GetIPGlobalProperties();
    IPEndPoint[] ipEndPoints = ipProperties.GetActiveTcpListeners();
    -------
    -------
    -------
}

I am showing the example coding.it was checking local IP and port and moving to next form.it will check local port and IP is available.if port and IP not available it will come to the initial stage and it was working fine.same thing i have to check in remote Port and IP.

like image 538
user3494471 Avatar asked Apr 07 '14 04:04

user3494471


People also ask

How can I tell if RDP port is open?

Navigate to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server and to HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows NT\Terminal Services. If the value of the fDenyTSConnections key is 0, then RDP is enabled. If the value of the fDenyTSConnections key is 1, then RDP is disabled.

How do I check if a port number is available?

You can use "netstat" to check whether a port is available or not. Use the netstat -anp | find "port number" command to find whether a port is occupied by an another process or not. If it is occupied by an another process, it will show the process id of that process.

How do I find my remote port number?

How do I find the port number of a specific IP address? All you have to do is type “netstat -a” on Command Prompt and hit the Enter button. This will populate a list of your active TCP connections. The port numbers will be shown after the IP address and the two are separated by a colon.


1 Answers

Use the Ping class of .NET to find out if the system is up and connected, the use the PortScanner to check if the port is open. check these links for further reading and exploring.

http://msdn.microsoft.com/en-us/library/system.net.networkinformation.ping%28v=vs.110%29.aspx

http://social.msdn.microsoft.com/Forums/vstudio/en-US/8e4410bd-307f-4264-9575-cd9882653945/help-with-portscanner-in-c?forum=csharpgeneral

OR

public static bool PingHost(string hostUri, int portNumber)
{
    try
    {
        using (var client = new TcpClient(hostUri, portNumber))
            return true;
    }
    catch (SocketException ex)
    {
        MessageBox.Show("Error pinging host:'" + hostUri + ":" + portNumber.ToString() + "'");
        return false;
    }
}
like image 93
Tauseef Avatar answered Oct 20 '22 01:10

Tauseef