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

推荐订阅源

W
WeLiveSecurity
T
The Exploit Database - CXSecurity.com
C
CXSECURITY Database RSS Feed - CXSecurity.com
S
Security @ Cisco Blogs
T
Threat Research - Cisco Blogs
TaoSecurity Blog
TaoSecurity Blog
Recent Commits to openclaw:main
Recent Commits to openclaw:main
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
腾讯CDC
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
T
The Blog of Author Tim Ferriss
Microsoft Azure Blog
Microsoft Azure Blog
罗磊的独立博客
F
Full Disclosure
博客园 - 【当耐特】
C
CERT Recently Published Vulnerability Notes
Engineering at Meta
Engineering at Meta
Application and Cybersecurity Blog
Application and Cybersecurity Blog
T
Threatpost
I
Intezer
V2EX - 技术
V2EX - 技术
H
Hackread – Cybersecurity News, Data Breaches, AI and More
The Hacker News
The Hacker News
小众软件
小众软件
Google DeepMind News
Google DeepMind News
T
Tailwind CSS Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
B
Blog RSS Feed
Microsoft Security Blog
Microsoft Security Blog
N
News | PayPal Newsroom
MyScale Blog
MyScale Blog
AI
AI
Vercel News
Vercel News
Spread Privacy
Spread Privacy
美团技术团队
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
The GitHub Blog
The GitHub Blog
V
Vulnerabilities – Threatpost
Schneier on Security
Schneier on Security
Cyberwarzone
Cyberwarzone
G
GRAHAM CLULEY
Help Net Security
Help Net Security
Hacker News: Ask HN
Hacker News: Ask HN
Google DeepMind News
Google DeepMind News
MongoDB | Blog
MongoDB | Blog
L
LINUX DO - 热门话题
U
Unit 42
L
LangChain Blog
Recent Announcements
Recent Announcements

博客园 - DarkAngel

好久未登陆 签到 Silverlight 3正式版新鲜出炉 Silverlight3的7个新功能[转] 读取DWG文件中的文本信息(CAD2004) WEBPART结合实际的应用(.Net2005) 带验证功能的的TextBox 一个很老的故事: 水和鱼的故事 Browser.Net浏览器c#开发(开源) 吉祥三宝(设计篇) - DarkAngel - 博客园 将指定网页添加到收藏夹的方法(c#) Microsoft.Press.Microsoft.Visual.C.Sharp.2005.Step.by.Step.Oct.2005 取客户端MAC地址的方法 关于在活动目录(ACTIVE DIRECTORY)中创建组织单位和用户 Exchange 2k的安装与删除。 无 Cookie 的 ASP.NET 一个任意获得页面控件的方法 跨页面的多选功能实现 买不起笔记本,只好自己动手做一个啦-!(转)
一个端口扫描的小程序
DarkAngel · 2006-11-29 · via 博客园 - DarkAngel

  今天有个朋友让我帮他做个扫描端口的小程序,就是看某台机器打开了哪些端口,既然已经写了就顺便贴出来一下,虽然不是什么复杂东西,给相关需要的人参考一下吧:)下面是原代码

  1using System;
  2using System.Collections.Generic;
  3using System.ComponentModel;
  4using System.Data;
  5using System.Drawing;
  6using System.Text;
  7using System.Windows.Forms;
  8using System.Threading;
  9using System.Net;
 10using System.Net.Sockets;
 11
 12namespace Scan
 13{
 14    public partial class Main : Form
 15    {
 16        //主线程
 17        private Thread tdm;
 18        //开始端口,结束端口
 19        int Start, End;
 20       //线程数
 21        private int count=0;
 22        //当前扫描端口
 23        private int i;
 24        public Main()
 25        {
 26            InitializeComponent();
 27        }

 28        /// <summary>
 29        /// 副线程
 30        /// </summary>

 31     private void Process()
 32        {
 33         //当前要扫描的IP地址
 34            string IP;
 35        
 36            IP = mkIP.Text;
 37
 38                TcpClient tc = new TcpClient();
 39                tc.SendTimeout = tc.ReceiveTimeout = 20000;
 40
 41                try
 42                {
 43                    //建立连接
 44                    tc.Connect(IP, i);
 45                    //判断是否连接成功
 46                    if (tc.Connected)
 47                    {
 48                        tbDetail.Text = tbDetail.Text + "端口" + i.ToString() + "开放。\r\n";
 49                    }

 50                   
 51                }

 52                catch (Exception ex)
 53                {
 54                   
 55                }

 56                finally
 57                {
 58  tc.Close();
 59                    tc = null;
 60                    //修改线程数
 61                    count--;
 62//写入进度  
 63 pbProcess.Value = Convert.ToInt32((Convert.ToDouble(i) / Convert.ToDouble(End)) * 100);
 64                }

 65               
 66            
 67           
 68        }

 69
 70        private void button1_Click(object sender, EventArgs e)
 71        {
 72            Thread tmain = new Thread(new ThreadStart(MainProcess));
 73            tmain.Start();
 74           
 75        }

 76        //主线程
 77        private void MainProcess()
 78        {
 79            count = 0;
 80            pbProcess.Value = 0;
 81            tbDetail.Text = "";
 82 Start = Convert.ToInt32(tbStar.Text);
 83            End = Convert.ToInt32(tbEnd.Text);
 84            //循环取副线程扫描端口
 85            for (i = Start; i < End; i++)
 86            {
 87                count++;
 88               
 89                tdm = new Thread(new ThreadStart(Process));
 90                tdm.Start();
 91                Thread.Sleep(10);
 92                //线程数控制在20
 93                while (count > 20) ;
 94            }

 95           while (count>0) ;
 96            tbDetail.Text = tbDetail.Text+"扫描完成";
 97        }

 98        private void Main_Load(object sender, EventArgs e)
 99        {
100            Control.CheckForIllegalCrossThreadCalls = false;
101        }

102
103       
104    }

105   
106}