如何检查远程IP和端口可用? [英] How to check remote IP and Port is available?

查看:754
本文介绍了如何检查远程IP和端口可用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要检查远端IP和端口可用或not.If它可将移动到不存在,它应该初始state.I使用该

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

我显示的例子coding.it在检查本地IP和端口,并移动到下一个form.it将检查本地端口和IP是available.if端口, IP协议无法使用它会在最初的阶段,这是工作fine.same的事情,我在远程端口和IP检查。

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.

推荐答案

使用类.NET来看看系统启动并连接,使用端口扫描工具检查该端口是开放的。检查这些链接进一步阅读和探索。

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-端口扫描工具,在-C?论坛= csharpgeneral

下面一个很干净的方法

public static bool PingHost(string _HostURI, int _PortNumber)
{
    try
    {
        TcpClient client = new TcpClient(_HostURI, _PortNumber);
        return true;
    }
    catch (Exception ex)
    {
        MessageBox.Show("Error pinging host:'" + _HostURI + ":" + _PortNumber.ToString() + "'");
        return false;
    }
}

这篇关于如何检查远程IP和端口可用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆