资源简介
C# 实现的IP地址段端口扫描器,http://www.cnblogs.com/wk986/archive/2013/03/14/2960529.html

代码片段和文件信息
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.Net;
using System.Net.Sockets;
namespace ScanDemo
{
public partial class Form1 : Form
{
#region 声明变量
//已扫描端口数目
double scannedCount = 0;
//正在运行的线程数目
int runningThreadCount = 0;
//最大工作线程数
static int maxThread = 100;
//IP地址
string host = null;
//端口
int port = 1234;
int startIP=1;
int endIP=255;
string addresIP = “192.168.1.“;
#endregion
#region 窗体方法
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender EventArgs e)
{
this.Text = string.Format(“wk986 扫描IP段指定端口 {0}-{1}:{2}“
addresIP+startIPendIPport);
}
#endregion
#region 扫描方法
public void Scan(string m_host int m_port)
{
//我们直接使用比较高级的TcpClient类
TcpClient tc = new TcpClient();
//设置超时时间
tc.SendTimeout = tc.ReceiveTimeout = 2000;
try
{
//同步方法
//IPAddress ip = IPAddress.Parse(host);
//IPEndPoint IPendp = new IPEndPoint(ip port);
//tc.Connect(IPendp);
//异步方法
IAsyncResult oAsyncResult = tc.BeginConnect(m_host m_port null null);
oAsyncResult.AsyncWaitHandle.WaitOne(1000 true);//1000为超时时间
if (tc.Connected)
{
//如果连接上,证明此端口为开放状态
UpdateListBox(listBox1 m_host + “:“ + m_port.ToString());
}
}
catch (System.Net.Sockets.SocketException e)
{
//容错处理
//MessageBox.Show(“Port {0} is closed“ host.ToString());
//Console.WriteLine(e.Message);
}
finally
{
tc.Close();
tc = null;
scannedCount++;
runningThreadCount--;
}
}
#endregion
#region 按钮
private void button1_Click(object sender EventArgs e)
{
if (!backgroundWorker1.IsBusy)
{
listBox1.Items.Clear();
scannedCount = 0;
runningThreadCount = 0;
backgroundWorker1.RunWorkerAsync();
}
}
private void button2_Click(object sender EventArgs e)
{
backgroundWorker1.CancelAsync();
}
private void button3_Click(object sender EventArgs e)
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 7726 2013-03-14 22:34 IP端口扫描\ScanDemo\Form1.cs
文件 5797 2013-03-14 21:41 IP端口扫描\ScanDemo\Form1.Designer.cs
文件 6022 2013-03-14 21:41 IP端口扫描\ScanDemo\Form1.resx
文件 3541 2013-03-14 22:13 IP端口扫描\ScanDemo\Form2.cs
文件 7161 2013-03-14 22:05 IP端口扫描\ScanDemo\Form2.Designer.cs
文件 5817 2013-03-14 22:05 IP端口扫描\ScanDemo\Form2.resx
文件 489 2013-03-13 10:27 IP端口扫描\ScanDemo\Program.cs
文件 1348 2013-03-12 16:55 IP端口扫描\ScanDemo\Properties\AssemblyInfo.cs
文件 2868 2013-03-12 16:55 IP端口扫描\ScanDemo\Properties\Resources.Designer.cs
文件 5612 2013-03-12 16:55 IP端口扫描\ScanDemo\Properties\Resources.resx
文件 1095 2013-03-12 16:55 IP端口扫描\ScanDemo\Properties\Settings.Designer.cs
文件 249 2013-03-12 16:55 IP端口扫描\ScanDemo\Properties\Settings.settings
文件 4025 2013-03-14 21:16 IP端口扫描\ScanDemo\ScanDemo.csproj
文件 858 2013-03-14 21:48 IP端口扫描\ScanDemo\SearchEventArgs.cs
文件 1546 2013-03-13 22:03 IP端口扫描\ScanIP.sln
..A..H. 50176 2013-03-14 22:49 IP端口扫描\ScanIP.suo
..A..H. 29696 2013-03-13 22:01 IP端口扫描\ScanIP.v11.suo
目录 0 2013-03-13 22:00 IP端口扫描\ScanDemo\Properties
目录 0 2013-03-14 22:49 IP端口扫描\ScanDemo
目录 0 2013-03-13 22:01 IP端口扫描
----------- --------- ---------- ----- ----
134026 20
- 上一篇:C#用GDI+画图经典案例不下后悔
- 下一篇:C#版USB通信编程(接收和发送数据)
相关资源
- C# OCR数字识别实例,采用TessnetOcr,对
- 考试管理系统 - C#源码
- asp.net C#购物车源代码
- C#实时网络流量监听源码
- C#百度地图源码
- Visual C#.2010从入门到精通配套源程序
- C# 软件版本更新
- C#屏幕软键盘源码,可以自己定制界面
- 020ASP.NET车辆综合管理系统.zip
- 智慧城市 智能家居 C# 源代码
- c#获取mobile手机的IMEI和IMSI
- C#实现简单QQ聊天程序
- 操作系统 模拟的 欢迎下载 C#版
- C#写的计算机性能监控程序
- 用C#实现邮件发送,有点类似于outlo
- MVC model层代码生成器 C#
- c#小型图书销售系统
- C# Socket Server Client 通讯应用 完整的服
- c# winform 自动登录 百度账户 源代码
- C#编写的16进制计算器
- C#TCP通信协议
- C# 数据表(Dataset)操作 合并 查询一
- C#语音识别系统speechsdk51,SpeechSDK51L
- 数据库备份还原工具1.0 C# 源码
-
[免费]xm
lDocument 节点遍历C# - EQ2008LEDc#开发实例
- DirectX.Capturec# winform 操作摄像头录像附
- c# 实现的最大最小距离方法对鸢尾花
- C#版保龄球记分代码
- C#自定义控件
评论
共有 条评论