我在 C# 中制作了一个端口扫描器,但我似乎无法让它更快:
private void Scan()
{
int startPort = Convert.ToInt32(txtFrom.Text);
int endPoint = Convert.ToInt32(txtTo.Text);
progressBar1.Value = 0;
progressBar1.Maximum = endPoint - startPort + 1;
for (int currPort = startPort; currPort <= endPoint; currPort++)
{
TcpClient tcpportScan = new TcpClient();
tcpportScan.SendTimeout = 10;
try
{
tcpportScan.Connect(txtIPaddress.Text, currPort);
txtDisplay.AppendText("Port " + currPort + " open.\n");
}
catch (Exception)
{
txtDisplay.AppendText("Port " + currPort + " closed.\n");
}
progressBar1.PerformStep();
}
}
有谁知道如何加快这个过程?