我正在尝试在 C# 中创建端口扫描器,到目前为止我有这个:
private void ip()
{
int start = 70;
int end = 80;
string ipString;
if (this.comboBox1.Text == "Domain") {
ipString= Dns.GetHostEntry(txtHost.Text).AddressList[0].ToString();
}
else {
ipString = txtHost.Text;
}
TcpClient asd = new TcpClient();
// MessageBox.Show(ipString);
IPAddress address = IPAddress.Parse(ipString);
for (int i = start; i <= end; i++)
{
try
{
asd.SendTimeout = 3000;
asd.ReceiveTimeout = 3000;
asd.Connect(address, i);
if (asd.Connected)
{
MessageBox.Show("Port " + i + " is open");
}
}
catch
{
MessageBox.Show("Port " + i + " is closed");
}
}
}
但是对于封闭的端口,它有点慢,大约 20 秒,我应该怎么做才能让这个过程更快?非常感谢。