检查ip with port是否可用? [英] Checking if ip with port is available?

查看:212
本文介绍了检查ip with port是否可用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要知道如何检查带端口的IP是否正在连接。
端口是7171,我使用的是Visual Studio C#Express 2010 .NET。

I need to know how to check if an IP with Port is working to connect to. Port is 7171, and I'm using Visual Studio C# Express 2010 .NET.

推荐答案

检查ip是工作中,您可以使用代码执行ping操作并从代码中打开cmd。

To check ip is working you can do a ping using your code and opening cmd from your code.

假设您正在使用tcpclint,您可以检查端口是否空闲:

You can check if port is free assuming you are using tcpclint :

int port = 456; //<--- This is your value
bool isAvailable = true;

IPGlobalProperties ipGlobalProperties = IPGlobalProperties.GetIPGlobalProperties();
 TcpConnectionInformation[] tcpConnInfoArray = ipGlobalProperties.GetActiveTcpConnections();

 foreach (TcpConnectionInformation tcpi in tcpConnInfoArray)
 {
   if (tcpi.LocalEndPoint.Port==port)
   {
     isAvailable = false;
     break;
   }
 }

这篇关于检查ip with port是否可用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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