private void btnScan_Click(object sender, EventArgs e) { var ipSettings = CIDRSettingBiz.GetCIDRSettings(); sbScanResult = new StringBuilder(); //var ip1 = IPAddress.Parse("58.251.93.95"); //var ip2 = IPAddress.Parse("58.251.93.255"); var ip1 = IPAddress.Parse(ipSettings[0].IPStart); var ip2 = IPAddress.Parse(ipSettings[0].IPStart); var ipRange = IPScan.GetIPRange(ip1, ip2); List<IPScan> ipList = new List<IPScan>(); foreach (string ipstr in ipRange) { IPScan scan = new IPScan(); scan.IP = ipstr; scan.TTLFaZhiSet = ipSettings[0].TTLFaZhi; scan.TCPFaZhiSet = ipSettings[0].TCPFaZhi; scan.TCPPortSet = ipSettings[0].TCPPort; ipList.Add(scan); } // start scan //foreach (var ip in ipList) //{ Thread t = new Thread(new ParameterizedThreadStart(IPScanProcess)); // parameter t.Start(ipList); //} }
private List<IPScan> GetScanIPListPerThread() { lock (this) { List<IPScan> result = new List<IPScan>(); int ipCountIndex = 0; long ipNum = NextScanStartIPNum; foreach (var cidr in CIDRSettingsForScan) { if(NextScanStartIPNum == 0) { NextScanStartIPNum = cidr.IPStartNum; ipNum = NextScanStartIPNum; } if(NextScanStartIPNum >= cidr.IPStartNum && NextScanStartIPNum <= cidr.IPEndNum) { while (ipCountIndex < SCAN_COUNT_PER_THREAD && ipNum <= cidr.IPEndNum) { IPScan scan = new IPScan(); scan.IP = IPConverter.long2ip(ipNum); scan.TTLFaZhiSet = cidr.TTLFaZhi; scan.TCPFaZhiSet = cidr.TCPFaZhi; scan.TCPPortSet = cidr.TCPPort; if (!String.IsNullOrEmpty(cidr.TTLExceptionKeys)) { scan.ExceptionKeys = cidr.TTLExceptionKeys.Split(','); } result.Add(scan); ipNum++; ipCountIndex++; } } if (ipCountIndex == SCAN_COUNT_PER_THREAD) { NextScanStartIPNum = ipNum; break; } else { NextScanStartIPNum = 0; } } LastIPCountInLastThread = result.Count; return result; } }