tags:

views:

331

answers:

3

Supposing i know the ip of a pc, is it possible to test if that pc supports remote connection? (windows case)

A: 

This appears to work:

http://www.yougetsignal.com/tools/open-ports/

Type in the IP address and then use port "3389" to check for native windows remote desktop.

Jefe
thanks for replys..i understand that i must check port 3389..i belive it will be kinda slow if i make it using c# any suggestions guys?
how do you define "kinda slow"? :)
Jørn Schou-Rode
A: 

One way to test if Remote Desktop is available, could be to open a socket to the default RD port (3389). If a connection can be established, assume that RD is available and drop the socket. If connection is refused, RD is most likely not available.

Another approach would be to access information about RD via WMI. This would require the client computer to have sufficient user rights on the (possible) server, though. Inspiration for this approach can be found here:

http://www.vedivi.com/support/blog/71-how-to-enable-remote-desktop-programmatically.html

Jørn Schou-Rode
A: 

i figured it out like this

        private bool TestPort(string ipString,int port)
        {
            IPAddress ip = IPAddress.Parse(ipString);
            bool test = false;
            try
            {
                System.Net.Sockets.Socket s = new System.Net.Sockets.Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                s.Connect(ip, port);
                if (s.Connected == true)
                    test = true;
                s.Close();
            }
            catch (SocketException ex)
            {
                    test = false;
            }
            return test;
        }

if the function were in c++ would it be faster? how much faster? any suggestions?