c#并行扫描端口控制台程序
- 作者: 五速梦信息网
- 时间: 2026年04月04日 13:49
static void Main(string[] args)
{<br/>
Console.WriteLine("请输入ip");<br/>
string ip = Console.ReadLine();<br/>
Parallel.For(1, 65535, i => scan(ip, i, 200));<br/>
Console.WriteLine("扫描完成");
}
public static void scan(string ip, int port, int timeout)
{<br/>
TcpClient tc = new TcpClient();<br/>
tc.ReceiveTimeout = timeout;<br/>
try<br/>
{<br/>
tc.Connect(ip, port);<br/>
if (tc.Connected)<br/>
{<br/>
Console.WriteLine("Port {0} is Open", port.ToString().PadRight(6));<br/>
Console.WriteLine("连接成功!!!");<br/>
}<br/>
}<br/>
catch<br/>
{<br/>
//Console.WriteLine("Port {0} is Closed", port.ToString().PadRight(6));<br/>
}<br/>
finally<br/>
{<br/>
tc.Close();<br/>
tc = null;
}
}
- 上一篇: c#动态为类添加属性
- 下一篇: C#Light Unity逻辑热更新解决方案0.20 发布
相关文章
-
c#动态为类添加属性
c#动态为类添加属性
- 互联网
- 2026年04月04日
-
C#读取excel文件,并生成json
C#读取excel文件,并生成json
- 互联网
- 2026年04月04日
-
C#读取Excel文件:通过OleDb连接,把excel文件作为数据源来读取
C#读取Excel文件:通过OleDb连接,把excel文件作为数据源来读取
- 互联网
- 2026年04月04日
-
C#Light Unity逻辑热更新解决方案0.20 发布
C#Light Unity逻辑热更新解决方案0.20 发布
- 互联网
- 2026年04月04日
-
C#+HtmlAgilityPack+XPath带你采集数据(以采集天气数据为例子)
C#+HtmlAgilityPack+XPath带你采集数据(以采集天气数据为例子)
- 互联网
- 2026年04月04日
-
C打包应用程序(安装程序卸载程序)
C打包应用程序(安装程序卸载程序)
- 互联网
- 2026年04月04日






