在C#如何检测某IP的某端口是否打开(类似于TELNET)? 如题 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 就是用Socket.Connect连接IP地址的指定端口...捕捉Exception..代码如下:static void Main(string[] args) { IPAddress ip = IPAddress.Parse("127.0.0.1"); for (int i = 0; i < 1024 ;i++) { try { IPEndPoint point = new IPEndPoint(ip,i); Socket sock = new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp); sock.Connect(point); Console.WriteLine("连接端口{0}成功!",point); }catch(SocketException e) { if (e.ErrorCode != 10061) { Console.WriteLine(e.Message); } Console.WriteLine("连接{0}失败", i); } } } 关于PropertyInfo.SetValue 方法 C#异步调用的困惑 关于C# 空值插入数据库datetime类型问题。 html转义字符的案怎么用C#来转义? 请教各位大虾,怎样判断C1FlexGrid中的单元格的内容是否为空? 图像边缘特征相似性比较 关于.net里带有的组件的问题 如何不装入全部文件就能读出文件的前两个字节 关于委托的入门级弱智问题 谁知道哪有Whidbey自带的Visio下载? 有一个程序访问internet的网页了,如何得到它访问的哪个网页? 请大家帮忙了!!
static void Main(string[] args)
{
IPAddress ip = IPAddress.Parse("127.0.0.1");
for (int i = 0; i < 1024 ;i++) {
try {
IPEndPoint point = new IPEndPoint(ip,i);
Socket sock = new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
sock.Connect(point);
Console.WriteLine("连接端口{0}成功!",point);
}catch(SocketException e) {
if (e.ErrorCode != 10061) {
Console.WriteLine(e.Message);
}
Console.WriteLine("连接{0}失败", i);
}
}
}