public PortScanner( string host, int portStart, int portStop, int timeout, DataGridView Gview, ToolStripProgressBar CurrentPortCount, Form t, Button button1) { this.host = host; portList = new PortList(portStart, portStop); tcpTimeout = timeout; view = Gview; this.CurrentPortCount = CurrentPortCount; f = t; this.button1 = button1; }
private static void HostThreadWorker(List <IPAddress> list, int nrOfHosts, int nrOfThreads, int i, MutexClass m) { int totalNrOfHosts = list.Count; int counter = 0; IPAddress ipAddrScanned = new IPAddress(0); PortList portListing = new PortList(1, 600); Cde cdeobj = new Cde(); cdeobj._countdownEvent = new CountdownEvent(nrOfThreads); while ((i + counter) <= (totalNrOfHosts - 1)) { { ipAddrScanned = list[i + counter]; portListing = new PortList(1, 65535); cdeobj = new Cde(); cdeobj._countdownEvent = new CountdownEvent(nrOfThreads); m._mutex.WaitOne(); try { counter += nrOfHosts; } finally { m._mutex.ReleaseMutex(); } } string str = string.Concat("Machine ", ipAddrScanned, " is being scanned"); Console.WriteLine(str); str.WriteDebug(); for (int j = 0; j < nrOfThreads; j++) { int k = j; IPAddress ip = ipAddrScanned; PortList p = portListing; Cde cdevent = cdeobj; var portThread = new Thread(() => PortThreadWorker(ip, k, cdevent, p)); portThread.Start(); } cdeobj._countdownEvent.Wait(); } }
private static void PortThreadWorker(IPAddress ipAddrScannned, int j, Cde cdeevent, PortList portListing) { TcpClient tcpClientobj = new TcpClient(); UdpClient udpClientobj = new UdpClient(); Mutex mut = new Mutex(); int port = 1; while (port != -1) { mut.WaitOne(); try { port = portListing.getNext(); } finally { mut.ReleaseMutex(); } try { tcpClientobj = new TcpClient(ipAddrScannned.ToString(), port); udpClientobj = new UdpClient(ipAddrScannned.ToString(), port); } catch { continue; } finally { try { tcpClientobj.Close(); udpClientobj.Close(); } catch { } } string s = string.Concat("Port ", port, " is open on machine ", ipAddrScannned); Console.WriteLine(s); s.WriteDebug(); } cdeevent._countdownEvent.Signal(); }
public PortScanner(string host, int portStart, int portStop, ILog log) { this._host = host; this._portList = new PortList(portStart, portStop); this._log = log; }
public PortScanner(string host, int portStart, int portStop) { this.host = host; this.portList = new PortList(portStart, portStop); }