如何检查远程IP和端口可用? [英] How to check remote IP and Port is available?
问题描述
我要检查远端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
或
下面一个很干净的方法
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屋!