コード例 #1
0
 public static void CreateConfigFile(string strFileName, bool bProbes)
 {
     using (FileStream fs = new FileStream(strFileName, FileMode.Create)) {
         byte[] byData = null;
         if (bProbes)
         {
             byData = ConfigerHelper.DeCompress(Properties.Resources.probes_compress);
         }
         else
         {
             byData = ConfigerHelper.DeCompress(Properties.Resources.defports_compress);
         }
         fs.Write(byData, 0, byData.Length);
     }
 }
コード例 #2
0
        static void Main(string[] args)
        {
            m_clr = Console.ForegroundColor;
            //args = "-h 192.140.145.127 -smb".Split(' ');
            //args = "-h 192.168.10.2 -p 80 -r 10 -tt 10000".Split(' ');
            //args = "-hf ./vultrcidrs.txt -order port -st -cd 0 -con 12000".Split(' ');
            //args = "-h 46.101.181.209/0 -order port -st -cd 0 -con 8000".Split(' ');
            //args = "-h 45.32.249.1/24 -order port -st -cd 1".Split(' ');
            if (args.Length < 2)
            {
                ScannerStatic.ShowInfo();
                return;
            }
            if (!File.Exists("./config_defports.st"))
            {
                ConfigerHelper.CreateConfigFile("./config_defports.st", false);
            }
            if (!File.Exists("./config_probes.st"))
            {
                ConfigerHelper.CreateConfigFile("./config_probes.st", true);
            }
            m_pc = new ProbeConfiger(
                File.ReadAllText("./config_probes.st"),
                File.ReadAllText("./config_defports.st")
                );
            try {
                m_scanner            = ScannerStatic.InitScanner(args, m_pc);
                m_scanner.Completed += new ScanEventHandler(m_scanner_Completed);
            } catch (Exception ex) {
                var clr = Console.ForegroundColor;
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(ex.Message + "\r\n\t" + (ex.InnerException != null ? ex.InnerException.Message : ""));
                Console.ForegroundColor = clr;
                Console.Write("Show help info?(y/n):");
                if (Console.ReadKey().KeyChar == 'y')
                {
                    ScannerStatic.ShowInfo();
                }
                return;
            }
            DateTime dt = DateTime.Now;

            m_se = new Semaphore(ScannerConfiger.Concurrent, ScannerConfiger.Concurrent);
            new Thread(Program.ShowPregress)
            {
                IsBackground = true
            }.Start();
            if (ScannerConfiger.IsIcmp)
            {
                IcmpScanner icmp = new IcmpScanner(ScannerConfiger.Concurrent);
                icmp.Completed += new IcmpEventHandler(icmp_Completed);
                new Thread(Program.IcmpFlushCallBack)
                {
                    IsBackground = true
                }.Start();
                foreach (var v in ScannerConfiger.IPRange)
                {
                    for (uint i = v.Start; i <= v.End; i++)
                    {
                        m_se.WaitOne();
                        lock (m_obj_sync) {
                            m_nRunning++;
                            m_nTaskCount++;
                        }
                        icmp.Ping(new IPAddress(ScannerStatic.Reverse(i)), ScannerConfiger.Timeout, ScannerConfiger.Retry);
                    }
                }
            }
            else
            {
                if (ScannerConfiger.ScanningOrder == "host")
                {
                    Program.ScanFromHost();
                }
                else if (ScannerConfiger.ScanningOrder == "port")
                {
                    Program.ScanFromPort();
                }
                else
                {
                    Program.ScanFromRnd();
                }
            }
            while (m_nTaskCount != m_nRuned)
            {
                Thread.Sleep(500);
            }
            Console.WriteLine("Queue:" + (m_nTaskCount - m_nRuned) + "  Running:" + m_nRunning + "  Runed:" + m_nRuned + "  Result:" + m_nResult + "  Jumped:" + m_nJumped);
            string strTimeSub = DateTime.Now.Subtract(dt).ToString();

            strTimeSub = strTimeSub.Substring(0, strTimeSub.LastIndexOf(':') + 3);
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("TIME: [" + dt.ToString("yy-MM-dd_HH:mm:ss") + "]-[" + DateTime.Now.ToString("yy-MM-dd_HH:mm:ss") + "] [" + strTimeSub + "]");
            Console.ForegroundColor = m_clr;
            //Console.ReadKey();
        }