多线程TCP扫描仪

时间:2013-03-11 19:30:28

标签: c#

我是C#多线程的新手。以下是我到目前为止的情况:

public void TnTThread()
{
   string[] lServer = txtServerList.Lines; 
   int ServerIdx;
   //each ip/host ex: 192.168.1.20
   for (ServerIdx = 0; ServerIdx < lServer.Length; ServerIdx++)
   {
      ThreadCount = Convert.ToInt32(tbThread.Value);
      ThreadScan = new System.Threading.Thread[ThreadCount];
      server_to_scan = lServer[ServerIdx].Trim ();
      for (int i = 0; i <= (ThreadScan.Length - 1); i++)
      {
         ThreadScan[i] = new System.Threading.Thread(new ThreadStart(Port_Scan)); //thread Port_scan
         ThreadScan[i].Name = "Thread " + i;
         ThreadScan[i].IsBackground = true;
         ThreadScan[i].Start();
         lblThreadInfo.Text = "Active Threads [" + (i + 1) + "] -> Scanning: " + server_to_scan;
         lblThreadInfo.Refresh();
      } // end for loop
      //System.Threading.Thread.Sleep(200);
   }
}

private void Port_scan()
{
    //scan all specified ports
}

上面的代码循环遍历整个lServer阵列列表,然后只扫描lServer中的最后一个IP / Server。如何让它通过每个服务器进行循环并进行端口扫描?

0 个答案:

没有答案