测试可能的远程连接

发布于 2024-07-25 14:54:45 字数 46 浏览 3 评论 0原文

假设我知道一台电脑的IP,是否可以测试该电脑是否支持远程连接? (窗户情况)

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

幸福还没到 2024-08-01 14:54:45

我是这样想的,

        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;
        }

如果这个函数是用c++写的,会更快吗? 快多少? 有什么建议么?

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?

梦巷 2024-08-01 14:54:45

这似乎有效:

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

输入 IP 地址,然后使用端口“3389”检查本机 Windows 远程桌面。

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.

少跟Wǒ拽 2024-08-01 14:54:45

测试远程桌面是否可用的一种方法是打开默认 RD 端口 (3389) 的套接字。 如果可以建立连接,则假定 RD 可用并丢弃套接字。 如果连接被拒绝,RD 很可能不可用。

另一种方法是通过 WMI 访问有关 RD 的信息。 不过,这需要客户端计算机在(可能的)服务器上拥有足够的用户权限。 这种方法的灵感可以在这里找到:

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文