惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

D
Darknet – Hacking Tools, Hacker News & Cyber Security
V
Vulnerabilities – Threatpost
Cloudbric
Cloudbric
G
GRAHAM CLULEY
S
Securelist
Schneier on Security
Schneier on Security
Help Net Security
Help Net Security
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Project Zero
Project Zero
Spread Privacy
Spread Privacy
P
Privacy International News Feed
C
Cyber Attacks, Cyber Crime and Cyber Security
Cisco Talos Blog
Cisco Talos Blog
T
Tailwind CSS Blog
博客园_首页
有赞技术团队
有赞技术团队
Simon Willison's Weblog
Simon Willison's Weblog
Stack Overflow Blog
Stack Overflow Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Latest news
Latest news
T
Tor Project blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Attack and Defense Labs
Attack and Defense Labs
www.infosecurity-magazine.com
www.infosecurity-magazine.com
O
OpenAI News
J
Java Code Geeks
T
Tenable Blog
K
Kaspersky official blog
AWS News Blog
AWS News Blog
S
Security @ Cisco Blogs
The GitHub Blog
The GitHub Blog
T
Threatpost
月光博客
月光博客
H
Heimdal Security Blog
Security Latest
Security Latest
The Hacker News
The Hacker News
Y
Y Combinator Blog
A
Arctic Wolf
Apple Machine Learning Research
Apple Machine Learning Research
C
Cisco Blogs
美团技术团队
Microsoft Security Blog
Microsoft Security Blog
Hugging Face - Blog
Hugging Face - Blog
T
The Blog of Author Tim Ferriss
C
CERT Recently Published Vulnerability Notes
D
Docker
Google Online Security Blog
Google Online Security Blog
D
DataBreaches.Net
V
Visual Studio Blog
H
Help Net Security

博客园 - sashow

c++知识点--extern "C"的作用 - sashow - 博客园 粘贴一点有用的东西留存-- Control 类的事件顺序 开始→运行→输入命令集锦 c#的ThreadPool使用笔记(三) c# 中Label 标签和.resx 文件中的换行问题 - sashow 计算某天是星期几的算法 find 和 grep 命令 - sashow Sql Server 中由数字转换为指定长度的字符串 [分享] C# 中 Socket 进行数据接收的一点心得 sql server 2005 使用问题总结 [转]解决无法显示所有文件和文件夹,无法显示隐藏文件和文件夹 FileStream进行Read() 操作后文件指针指向当前位置 用回车键模拟TAB键的方法 c#的ThreadPool使用笔记(二) c#的ThreadPool使用笔记(一) 人民币大小写转换(C#) 放弃还是继续? 随便写点东西 [转贴]Informix SQL函数的详细用法
c#的ThreadPool使用笔记(四)--实例:端口扫描程序
sashow · 2009-06-08 · via 博客园 - sashow

一个端口扫描程序就是对一段区域内的端口进行连接测试,如果能够连接上则标识这个端口是开放的。为了简化程序,我只是TCP连接方式的 端口进行扫描。为了加快扫描速度,我需要使用多线程,用ThreadPool对线程进行维护。

首先,定义一个端口扫描的类,该类实现对指定地址、指定端口进行扫描,并将扫描的结果(能、不能连接)保存 ,代码如下:(注意,为了加快端口扫描的速度,我对 Socket 的Connect采用异步方式,而信号灯等待1秒仍然没有得到结果,就认为没有连接到对方主机)

Code

 接下来就是,在多线程的环境中执行Scan了,代码如下:

Code

呵呵,这里用了比较 bt 的办法, WaitHandle.WaitAll (autoEvents);这是为了前面讲的原理写的,而为了不那么bt可以采用推拉窗技术。

好了,就说了这么多,一则希望能对大家有所帮助,二则希望自己将来写程序的时候,能够很快的进入状态。