端口扫描器
单一进程
在VS2019中
设计如图的界面
在Form1.cs中添加如下代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Threading;
using System.Net.Sockets;
namespace 端口扫描器
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false;
}
//自定义变量
// private int port;
private string Addr;
private bool[] done = new bool[65536];
private int start;
private int end;
// private Thread scanThread;
private bool OK;
private void txtStart_TextChanged(object sender, System.EventArgs e)
{
//获取输入的起始端口值
textBox1.Text = textBox2.Text;
}
private void txtEnd_TextChanged(object sender, System.EventArgs e)
{
//获取输入的结束端口值
textBox2.Text = textBox3.Text;
}
private void button1_Click(object sender, EventArgs e)
{
//创建线程,并创建ThreadStart委托对象
Thread process = new Thread(PortScan);
process.Start();
//显示端口扫描的范围
progressBar1.Minimum = Int32.Parse(textBox2.Text