网站导航免费论文 原创论文 论文搜索 原创论文 网学软件 学术大家 资料中心 会员中心 问题解答 原创论文 论文素材 设计下载 最新论文 下载排行 论文上传 在线投稿 联系我们
返回网学首页
网学联系
最新论文 推荐专题 热门论文 素材专题
当前位置: 网学 > 编程文档 > C# > 正文
C#编写的多线程端口扫描程序
来源:Http://myeducs.cn 联系QQ:点击这里给我发消息 作者: 用户投稿 来源: 网络 发布时间: 12/10/14
下载{$ArticleTitle}原创论文样式

作者: 萧寒雪

  有幸购买到Visual studio .net 的光盘,急忙安装一套,一用感觉非常好,所学写端口扫描程序一只,献给本版的朋友们:)
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
//增加的如下..
using System.Data;
using System.Net.Sockets;
using System.Net;
using System.IO;
using System.Text;
using System.Threading;

namespace iPortScan
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
//该处放的是程序要用到的公共变量
public string scanHost = Dns.GetHostName(); //默认当前本机IP
public Int32 tport = 0; //当前连接端口编号
public Int32 connState = 0; //扫描状态
public int portSum = 0 ; //端口总计
public bool endThread = false; //结束状态
public AutoResetEvent asyncOpsAreDone = new AutoResetEvent(false);
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox txtHostname;
private System.Windows.Forms.Button cmdExec;
private System.Windows.Forms.ListBox logList;
public System.Windows.Forms.CheckedListBox portList;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.NumericUpDown sNum;
private System.Windows.Forms.NumericUpDown eNum;
private System.Windows.Forms.CheckBox showdie;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.ToolTip toolTip1;
private System.Windows.Forms.StatusBar statusBar1;
private System.Windows.Forms.LinkLabel linkLabel1;
private System.Windows.Forms.LinkLabel linkLabel2;
private System.ComponentModel.IContainer components;
/*
此处省略了各个调用的控件的属性设置代码
*/
static void Main()
{
Application.Run(new Form1());
}

private void cmdExec_Click(object sender, System.EventArgs e)
{
Int32 startPort = (Int32)sNum.Value;
Int32 endPort = (Int32)eNum.Value;
if(txtHostname.Text.Length==0)
{
MessageBox.Show("请输入一个主机的名称吧!","系统提示");
txtHostname.Text = scanHost.ToString();
txtHostname.Focus();
return;
}
if(startPort>endPort)
{
MessageBox.Show("错误,起始端口必须要小于结束的端口!","系统提示");
startPort = endPort-1;
sNum.Text = startPort.ToString();
sNum.Focus();
return ;
}

if(cmdExec.Text=="&Scan")
{
endThread= false;
cmdExec.Text= "&Stop";
}
else
{
endThread= true;
cmdExec.Text= "&Scan";
}

if(endThread!=true)
{
connState = 0;
portSum = 0;
scanHost = txtHostname.Text;
try
{
IPAddress ipaddr =(IPAddress)Dns.Resolve(scanHost).AddressList.GetValue(0);
txtHostname.Text = ipaddr.ToString();
}
catch
{
txtHostname.Focus();
MessageBox.Show("请输入正确的主机地址,该地址DNS无法解析","系统提示");
return ;
}
logList.Items.Clear();

for (Int32 threadNum = startPort; threadNum <=endPort; threadNum++)
{
ThreadPool.QueueUserWorkItem(new WaitCallback(Startscan),threadNum);
logList.Items.Add ("扫描端口:&
  • 上一篇资讯: 用C#写计算器程序
  • 下一篇资讯: 利用C#重启远程计算机
  • 网学推荐

    免费论文

    原创论文

    浏览:
    设为首页 | 加入收藏 | 论文首页 | 论文专题 | 设计下载 | 网学软件 | 论文模板 | 论文资源 | 程序设计 | 关于网学 | 站内搜索 | 网学留言 | 友情链接 | 资料中心
    版权所有 QQ:3710167 邮箱:3710167@qq.com 网学网 [Myeducs.cn] 您电脑的分辨率是 像素
    Copyright 2008-2015 myeducs.Cn www.myeducs.Cn All Rights Reserved
    湘ICP备09003080号