/* Main */ private static void Main(string[] args) { ParseArgs(args); Console.SetWindowSize(100, 30); //Console.SetCursorPosition(0, 5); Console.BackgroundColor = ConsoleColor.Blue; Console.ForegroundColor = ConsoleColor.White; ConsoleKeyInfo cki; Console.WriteLine("Starting DnsTest with workstation name {0}", _wksName); Console.WriteLine("Touches autorisées: S pour search, G pour lister les serveurs, P pour purger les serveurs"); Console.WriteLine("Mode Hardcore {0}", _hardcore.ToString()); var rootzone = new RootZone(); // on charge la zone.root de l'iana. Check4PublicSuffixList(); DnsServer.Retries = _retries; DnsServer.Timeout = _timeout; // debuguer. /* * bool result; * string log; * var domain = DomainParser.DomainParser.Parse("fzbiuzhfizufizfzfz.fr"); * Console.WriteLine("{0} , {1} , {2}", domain.DomainName, domain.Libelle, domain.Extension); * var DnsServer = RootZone.GetServer(domain.DomainName)?.Ip; * RootZone.GetAll(); * DnsServer.IsNsRecorded(domain.DomainName, 2000, out result, out log, DnsServer); * Console.WriteLine(log); * * * * var domain2 = DomainParser.DomainParser.Parse("maktalent.xn--kprw13d"); * Console.WriteLine("{0} , {1} , {2}", domain2.DomainName, domain2.Libelle, domain2.Extension); * var DnsServer2 = RootZone.GetServer("xn--kprw13d")?.Ip; * RootZone.GetAll(); * DnsServer.IsNsRecorded("maktalent.xn--kprw13d", 2000, out result, out log, DnsServer2); * Console.WriteLine(log); * * Console.ReadKey(); */ var doneEvent = new AutoResetEvent(false); var taskPool = new TaskPool(_taskCount + 1); var dbDomains = new List <DomainDb.Domain>(); Full_List_Extensions = Full_List_Extensions.Except(List_Extensions).ToArray(); DomainDb.Db.ConnectionString = string.Format("Server={0};Database={1};Uid={2};Pwd={3};Port={4};MinimumPoolSize=16;maximumpoolsize=64;Charset=utf8;", _mySqlServer, _mySqlDatabase, _mySqlUsername, _mySqlPassword, 3306, _taskCount); Console.WriteLine("Init thread pool..."); var queueDomainPack = new Queue <List <DomainDb.Domain> >(); var sw = new Stopwatch(); Stopwatch swUpdate = new Stopwatch(); Task.Factory.StartNew(() => { while (true) { lock (lockObj) { RootZone.Purge(); } if (sw.IsRunning) { sw.Stop(); } if (swUpdate.IsRunning) { swUpdate.Stop(); } Console.WriteLine("Scanning..."); using (var db = new Db()) { Console.WriteLine("Reset libelle..."); db.ResetLibelle(_wksName); Thread.Sleep(1000); Console.WriteLine("Get For Processing..."); queueDomainPack.Enqueue(db.GetForProcessing(_wksName, _processBuffer)); } Console.WriteLine("Dequeue..."); dbDomains.Clear(); dbDomains = queueDomainPack.Dequeue(); Console.WriteLine("Querying {0} entries...", dbDomains.Count); if (!sw.IsRunning) { sw.Start(); } if (!swUpdate.IsRunning) { swUpdate.Start(); } for (int i = 0; i < dbDomains.Count; i++) { var i1 = i; //taskPool.QueueTask(async () => taskPool.QueueTask(() => { Interlocked.Increment(ref _libelles); bool insertion = false; Random rnd = new Random(); foreach (string List_Extension in List_Extensions.OrderBy(x => rnd.Next()).ToArray()) { var domainEntity = dbDomains[i1]; bool result; string log; domainEntity.DomainName = string.Concat(domainEntity.Libelle, List_Extension); //domainEntity.Extension = DomainParser.DomainParser.Parse(domainEntity.DomainName).Extension; domainEntity.Extension = List_Extension.Substring(1); var DnsServer = RootZone.GetServer(domainEntity.Extension)?.Ip; int thistimeout = _timeout; if (List_Extension == ".cn") { thistimeout = 2000; } if (List_Extension == ".cc") { thistimeout = 2000; } if (List_Extension == ".ca") { thistimeout = 1000; } if (List_Extension == ".co") { thistimeout = 500; } var thread = Thread.CurrentThread.ManagedThreadId; //var NsRecorded = await DnsServer.IsNsRecordedAsync(domainEntity.DomainName, thistimeout, DnsServer); //if (!NsRecorded.success) if (!DnsPerformer.DnsServer.IsNsRecorded(domainEntity.DomainName, domainEntity.Extension, thistimeout, out result, out log, DnsServer)) { Interlocked.Increment(ref _failed); domainEntity.Processing = null; } else { domainEntity.Processing = null; if (isWindows) { domainEntity.LastDate = TimeZoneInfo.ConvertTime(DateTime.Now, TimeZoneInfo.FindSystemTimeZoneById("Romance Standard Time")); } else { domainEntity.LastDate = TimeZoneInfo.ConvertTime(DateTime.Now, TimeZoneInfo.FindSystemTimeZoneById("Europe/Paris")); } domainEntity.NsRecorded = result; //domainEntity.NsRecorded = NsRecorded.result; if (domainEntity.NsRecorded == true) { if (_hardcore == true) { insertion = true; } Interlocked.Increment(ref _found); using (var db = new DomainDb.Db()) { if (db.Save(domainEntity)) { if (_hardcore == false) { insertion = true; } Interlocked.Increment(ref _inserted); } } } } } // foreach // repasse sur l'ensemble si première fois ou si on a detecté un nom dans la première liste. if (insertion == true || dbDomains[i1].LastDate == null) { //Console.WriteLine("[DEBUG] Passe complète sur " + dbDomains[i1].Libelle); foreach (string List_Extension in Full_List_Extensions.OrderBy(x => rnd.Next()).ToArray()) { var domainEntity = dbDomains[i1]; bool result; string log; domainEntity.DomainName = string.Concat(domainEntity.Libelle, List_Extension); domainEntity.Extension = List_Extension.Substring(1); var DnsServer = RootZone.GetServer(domainEntity.Extension)?.Ip; int thistimeout = _timeout; if (List_Extension == ".cn") { thistimeout = 2000; } if (List_Extension == ".cc") { thistimeout = 2000; } if (List_Extension == ".ca") { thistimeout = 500; } if (List_Extension == ".co") { thistimeout = 500; } var thread = Thread.CurrentThread.ManagedThreadId; if (!DnsPerformer.DnsServer.IsNsRecorded(domainEntity.DomainName, domainEntity.Extension, thistimeout, out result, out log, DnsServer)) { Interlocked.Increment(ref _failed); domainEntity.Processing = null; } else { domainEntity.Processing = null; if (isWindows) { domainEntity.LastDate = TimeZoneInfo.ConvertTime(DateTime.Now, TimeZoneInfo.FindSystemTimeZoneById("Romance Standard Time")); } else { domainEntity.LastDate = TimeZoneInfo.ConvertTime(DateTime.Now, TimeZoneInfo.FindSystemTimeZoneById("Europe/Paris")); } domainEntity.NsRecorded = result; if (domainEntity.NsRecorded == true) { using (var db = new Db()) { Interlocked.Increment(ref _found); if (db.Save(domainEntity)) { Interlocked.Increment(ref _inserted); insertion = true; } } } } } // foreach } }); //taskpool } // for buffer dbDomains taskPool.WaitAll(); dbDomains.Clear(); } //while true } , TaskCreationOptions.LongRunning); taskPool.WaitAll(); Task.Factory.StartNew(() => { int precedentQuery = 0; swUpdate.Restart(); while (true) { if (DnsServer.QueryNumber > 0 && dbDomains.Count > 0) { int maxworkerThreads; int maxportThreads; int availableworkerThreads; int availableportThreads; ThreadPool.GetMaxThreads(out maxworkerThreads, out maxportThreads); ThreadPool.GetAvailableThreads(out availableworkerThreads, out availableportThreads); var currentQuery = DnsServer.QueryNumber; stats.Enqueue((currentQuery - precedentQuery) / swUpdate.Elapsed.TotalSeconds); precedentQuery = currentQuery; swUpdate.Restart(); lock (lockObj) { // ouais ok y'avait plus propre. var console = Console.CursorTop; Console.ResetColor(); Console.SetCursorPosition(0, console); Console.Write(new string(' ', Console.WindowWidth)); Console.SetCursorPosition(0, console + 1); Console.Write(new string(' ', Console.WindowWidth)); Console.SetCursorPosition(0, console + 2); Console.Write(new string(' ', Console.WindowWidth)); Console.BackgroundColor = ConsoleColor.DarkGreen; Console.ForegroundColor = ConsoleColor.White; Console.SetCursorPosition(0, console + 3); Console.Write("{0}/{1} threads en cours / {2:0.000} QPS instantané / {3:0.000} QPS total / {4}/{5} libelles tested\n", maxworkerThreads - availableworkerThreads - 1, taskPool.GetTasks(), stats.Average(), DnsServer.QueryNumber / sw.Elapsed.TotalSeconds, _libelles, dbDomains.Count); Console.Write("{0} Domains tested / {1}% Fail / {2} Domains Found / {3} New Inserted\n", DnsServer.QueryNumber, (_failed / (float)DnsServer.QueryNumber) * 100, _found, _inserted); Console.SetCursorPosition(0, console); Console.BackgroundColor = ConsoleColor.Blue; Console.ForegroundColor = ConsoleColor.White; } } Thread.Sleep(1000); } }); do { cki = Console.ReadKey(); Console.TreatControlCAsInput = true; if (cki.Key == ConsoleKey.G) { lock (lockObj) { RootZone.GetAll(); } continue; } if (cki.Key == ConsoleKey.P) { lock (lockObj) { RootZone.Purge(); } continue; } if (cki.Key == ConsoleKey.S) { WriteLog("Extension à rechercher : "); lock (lockObj) { var extension = Console.ReadLine(); RootZone.GetExtension(extension); } continue; } else { WriteLog("Touches autorisées: S pour search, G pour lister les serveurs, P pour purger les serveurs"); } } while (cki.Key != ConsoleKey.Escape); sw.Stop(); Console.WriteLine(); Console.ReadKey(); } // Main
// ------------------------------------------ // ACCESSORS // ------------------------------------------ #region Accessors /// <summary> /// Gets the schema element with the specified ID. /// </summary> /// <param name="id">The ID of the meta object to consider.</param> /// <param name="parentMetobject1">The parent meta object to consider.</param> /// <returns>The bmeta object with the specified ID.</returns> public SchemaElement GetElementWithId(String id, SchemaElement parentMetobject1 = null) { return(RootZone?.GetElementWithId(id)); }