for (int CurrPort = 1; CurrPort <= 25; CurrPort++) { TcpClient TcpScan = new TcpClient(); try { // Try to connect TcpScan.Connect("192.168.0.1", CurrPort); // If there's no exception, we can say the port is open MessageBox.Show("Port " + CurrPort + " open"); } catch { // An exception occured, thus the port is probably closed MessageBox.Show("Port " + CurrPort + " closed"); } }
List<Task> tasks = new List<Task>(); for(int i =1;i<65535;i++) { Task t = Task.Factory.StartNew( () => portscan(i)); tasks.Add(t); } Task.WaitAll(tasks.ToArray());
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)