private async void LoadBtn_Click(object sender, EventArgs e) { string Path; using (OpenFileDialog FileDialog = new OpenFileDialog() { AddExtension = true, CheckFileExists = true, Filter = "txt files (*.txt)|*.txt", Multiselect = false, Title = "Select DNSBL urls" }) { if (FileDialog.ShowDialog() != DialogResult.OK) { return; } Path = FileDialog.FileName; } try { var No_Urls = await IPChecker.LoadUrlsAsync(Path); ResultBox.Text += $"{DateTime.Now.ToLongTimeString()} - Loaded {No_Urls} urls.{Environment.NewLine}"; } catch { MessageBox.Show("Invalid file."); } }
private async Task StartOperationAsync(string IP, CancellationToken CancellationToken = default) { int Counter = 0; await foreach (var Result in IPChecker.CheckIPAsync(Tools.ReverseIP(IP), CancellationToken)) { if (Tools.IsIPOk(Result.Value)) { if (ResultBox.InvokeRequired) { ResultBox.BeginInvoke(new Action(() => { ResultBox.Text += $"{Counter} - {DateTime.Now.ToLongTimeString()} - {Result.Key} >>> OK!{Environment.NewLine}"; })); } else { ResultBox.Text += $"{Counter} - {DateTime.Now.ToLongTimeString()} - {Result.Key} >>> OK!{Environment.NewLine}"; } } else { if (ResultBox.InvokeRequired) { ResultBox.BeginInvoke(new Action(() => { ResultBox.Text += $"{Counter} - {DateTime.Now.ToLongTimeString()} - {Result.Key} >>> BLOCKED!{Environment.NewLine}"; })); } else { ResultBox.Text += $"{Counter} - {DateTime.Now.ToLongTimeString()} - {Result.Key} >>> BLOCKED!{Environment.NewLine}"; } } Counter++; } ResultBox.Text += $"{DateTime.Now.ToLongTimeString()} - Finished!{Environment.NewLine}"; }
public IPListenerService(string ip) { Ip = ip; _ipChecker = new IPChecker(ip); _timer = new Timer(); _timer.Interval = 5000; _timer.AutoReset = true; _timer.Elapsed += OnTimerElapsed; }
public static IIPCheckerStrategy CreateIPChecker(IPChecker ipChecker) { switch (ipChecker) { case IPChecker.AWS: return(new AwsIPCheckerStrategy()); case IPChecker.DynDns: return(new DynDnsIPCheckerStrategy()); case IPChecker.Custom: return(new CustomIPCheckerStrategy()); default: throw new ArgumentException("Unknown IP Checker"); } }
private async void StartBtn_Click(object sender, EventArgs e) { if (OperationStarted) { CancellationTokenSource.Cancel(); return; } else { CancellationTokenSource = new CancellationTokenSource(); } if (string.IsNullOrWhiteSpace(IPBox.Text) || !IPAddress.TryParse(IPBox.Text, out _) || !IPChecker.AreUrlsLoaded()) { MessageBox.Show("Make sure to load the DNSBL urls and enter a valid IP.", "Invalid IP or DNSBL", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } OperationStarted = true; ClearBtn.Enabled = false; LoadBtn.Enabled = false; CurrentIPCheck.Enabled = false; StartBtn.Text = "Stop"; Tooltip.SetToolTip(StartBtn, "Stop the ongoing check operation."); ToggleLoader(); try { await StartOperationAsync(IPBox.Text, CancellationTokenSource.Token); } catch (OperationCanceledException) { ResultBox.Text += $"{DateTime.Now.ToLongTimeString()} - Operation cancelled!{Environment.NewLine}"; } catch (Exception ex) { MessageBox.Show($"Error:\n{ex.Message}"); } OperationStarted = false; StartBtn.Text = "Start"; Tooltip.SetToolTip(StartBtn, "Start the checking operation."); ClearBtn.Enabled = true; LoadBtn.Enabled = true; CurrentIPCheck.Enabled = true; ToggleLoader(); }
public void TestIsValidIPv4NiR(string ip) { Assert.AreEqual(IPChecker.IPv4Class.NiR, IPChecker.IsValidIPv4(ip)); }