I am trying to create port scanner in C#, so far I have this:
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");
}
}
}
However for closed ports, it's kinda slow, around 20 seconds, what should I do to make the process faster? Thanks a lot.