I created very simple scanner that will take ip range, get random ip within this range and check if particular port is opened. I use TcpClient
string PORT_CHECK(string IPorNAME, int port)
{
TcpClient tcpClient = new TcpClient();
tcpClient.ReceiveTimeout = 10000;
tcpClient.SendTimeout = 10000;
try
{
tcpClient.Connect(IPorNAME, port);
return IPorNAME + " : OPEN";
}
catch (Exception)
{
return IPorNAME + " : CLOSED";
}
}
I use threadpool
void main()
{
while (stopper == false)
{
ThreadPool.QueueUserWorkItem(new WaitCallback(bGround));
Thread.Sleep(1);
}
}
It checks about 10 ips per second, for example a scanner like VNC achieves a speed of about 500 per second, where this major difference comes from, and what to do to speed up my code?