国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
利用C#設(shè)計(jì)制作端口掃描器
主要使用到的是System.Net和System.Threading名稱空間。
1
2using System;
3using System.Collections.Generic;
4using System.Text;
5
6using System.Net;
7using System.Net.Sockets;
8
9using System.Threading;
10
11namespace PortScanner
12{
13 class Program
14 {
15  //已掃描端口數(shù)目
16  internal static int scannedCount = 0;
17  //正在運(yùn)行的線程數(shù)目
18  internal static int runningThreadCount = 0;
19  //打開的端口數(shù)目
20  internal static List<int> openedPorts = new List<int>();
21  //起始掃描端口
22  static int startPort = 1;
23  //結(jié)束端口號(hào)
24  static int endPort = 500;
25  //最大工作線程數(shù)
26  static int maxThread = 100;
27  static void Main(string[] args)
28  {
29   //接收傳入?yún)?shù)一作為要掃描的主機(jī)
30   string host = args[0];
31   //接收傳入?yún)?shù)二作為端口掃描范圍,如1-4000
32   string portRange = args[1];
33   startPort = int.Parse(portRange.Split('-')[0].Trim());
34   endPort = int.Parse(portRange.Split('-')[1].Trim());
35
36   for (int port = startPort; port < endPort; port++)
37   {
38    //創(chuàng)建掃描類
39    Scanner scanner = new Scanner(host, port);
40    Thread thread = new Thread(new ThreadStart(scanner.Scan));
41    thread.Name = port.ToString();
42    thread.IsBackground = true;
43    //啟動(dòng)掃描線程
44    thread.Start();
45
46    runningThreadCount++;
47
48    Thread.Sleep(10);
49    //循環(huán),直到某個(gè)線程工作完畢才啟動(dòng)另一新線程,也可以叫做推拉窗技術(shù)
50    while (runningThreadCount >= maxThread) ;
51   }
52
53   //空循環(huán),直到所有端口掃描完畢
54   while (scannedCount + 1 < (endPort - startPort)) ;
55
56    Console.WriteLine();
57    Console.WriteLine();
58    //輸出結(jié)果
59    Console.WriteLine("Scan for host: {0} has been completed , \n total {1} ports
scanned, \nopened ports :{2}",
60 host, (endPort - startPort), openedPorts.Count);
61
62   foreach (int port in openedPorts)
63    Console.WriteLine("\tPort: {0} is open", port.ToString().PadLeft(6));
64  }
65 }
66
67 //掃描類
68 class Scanner
69 {
70  string m_host;
71  int m_port;
72
73  public Scanner(string host, int port)
74  {
75   m_host = host; m_port = port;
76  }
77
78  public void Scan()
79  {
80   //我們直接使用比較高級(jí)的TcpClient類
81   TcpClient tc = new TcpClient();
82   //設(shè)置超時(shí)時(shí)間
83   tc.SendTimeout = tc.ReceiveTimeout = 2000;
84   try
85   {
86    //Console.Write("Checking port: {0}", m_port);
87    //嘗試連接
88    tc.Connect(m_host, m_port);
89    if (tc.Connected)
90    {
91     //如果連接上,證明此商品為開放狀態(tài)
92     Console.WriteLine("Port {0} is Open", m_port.ToString().PadRight(6));
93     Program.openedPorts.Add(m_port);
94    }
95   }
96   catch (System.Net.Sockets.SocketException e)
97   {
98    //容錯(cuò)處理
99    Console.WriteLine("Port {0} is closed", m_port.ToString().PadRight(6));
100    //Console.WriteLine(e.Message);
101   }
102   finally
103   {
104    tc.Close();
105    tc = null;
106    Program.scannedCount++;
107    Program.runningThreadCount--;
108
109    //Console.WriteLine(Program.scannedCount);
110
111   }
112  }
113 }
114}
115
116
117
 

本文轉(zhuǎn)自 ☆★ 包羅萬象網(wǎng)★☆ - http://www.baoluowanxiang.com 轉(zhuǎn)載請(qǐng)注明出處,侵權(quán)必究!
原文鏈接:http://www.baoluowanxiang.com/a/program/csharp/2010/0417/465.html
本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
利用Java實(shí)現(xiàn)端口掃描器
C語言下的端口掃描代碼
C#隊(duì)列學(xué)習(xí)筆記:RabbitMQ延遲隊(duì)列
Consul服務(wù)發(fā)現(xiàn)在windows下簡單使用
C#做了個(gè)多線程網(wǎng)絡(luò)通信的例子
ahjesus約束方法或?qū)傩缘恼{(diào)用方
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服