public IPsItem GetIpsItemFromDomainItem(DomainsItem dominio) { IPsItem ip = null; var po = new ParallelOptions(); if (Program.cfgCurrent.ParallelDnsQueries != 0) { po.MaxDegreeOfParallelism = Program.cfgCurrent.ParallelDnsQueries; } Parallel.For(0, Program.data.computerDomains.Items.Count, po, delegate(int i) { if (dominio == computerDomains.Items[i].Domain) { for (int c = 0; c < computerIPs.Items.Count; c++) { if (computerIPs.Items[c].Computer.name == computerDomains.Items[i].Computer.name) { ip = computerIPs.Items[c].Ip; return; } } } }); return(ip); }
private static void AddNew(IPsItem item) { try { item.IdProject = Program.data.Project.Id; CurrentContextDb.Ips.Add(item); } catch (DbEntityValidationException ex) { throw new DbEntityValidationException(ex.Message); } }
private static void Update(IPsItem item) { var ipItem = CurrentContextDb.Ips.FirstOrDefault(x => x.Id == item.Id); if (ipItem != null) { ipItem.Information = item.Information; ipItem.Ip = item.Ip; ipItem.Source = item.Source; ipItem.ZoneTransfer = item.ZoneTransfer; ipItem.activeDNS = item.activeDNS; } }
/// <summary> /// Add an IP only if it is valid /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btAddIp_Click(object sender, EventArgs e) { if ((txtOct4.Text == @"0") || (txtOct4.Text == @"255")) { MessageBox.Show(@"Invalid IP address", @"Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } try { var oct1 = int.Parse(txtOct1.Text); var oct2 = int.Parse(txtOct2.Text); var oct3 = int.Parse(txtOct3.Text); var oct4 = int.Parse(txtOct4.Text); if ((oct1 >= 0) && (oct1 <= 255) && (oct2 >= 0) && (oct2 <= 255) && (oct3 >= 0) && (oct3 <= 255) && (oct4 >= 0) && (oct4 <= 255)) { strIp = oct1 + "." + oct2 + "." + oct3 + "." + oct4; } else { MessageBox.Show(@"Invalid IP address", @"Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } IPsItem ip = Program.data.GetIp(strIp); if (ip == null || String.IsNullOrWhiteSpace(ip.Ip)) { var t = new Thread(AddIp); t.Start(); MessageBox.Show(@"Successfully added IP", @"Done", MessageBoxButtons.OK, MessageBoxIcon.Information); Close(); } else { MessageBox.Show(@"IP address already exists in the project", @"Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch { MessageBox.Show(@"Invalid IP address", @"Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Return IpItem by ip /// </summary> /// <param name="ip"></param> /// <returns></returns> public IPsItem GetIp(string ip) { ip = ip.Trim(); if (GetIpType(ip) == AddressFamily.InterNetworkV6) { ip = IPAddress.Parse(ip).ToString(); } IPsItem res; try { res = Ips.Items.First(x => x.Ip == ip); } catch { res = new IPsItem("", ""); } return(res); }
/// <summary> /// Add Ip. /// </summary> /// <param name="ip"></param> /// <param name="source"></param> /// <param name="domainSource"></param> public void AddIP(string ip, string source, string domainSource, int MaxRecursion, bool doptr) { ip = ip.Trim(); if (isIPv6(ip)) { ip = ParseIPV6(ip); } if (!Ips.Items.Any(I => I.Ip.ToLower() == ip.ToLower())) { if (isPublicIP(ip)) { var isInNetrange = Project.IsIpInNetrange(ip); if (!isInNetrange) { var host = string.Empty; try { host = Dns.GetHostEntry(ip).HostName; if (Program.data.Project.LstNetRange.Count == 0) { if (Program.data.Project.Domain != null) { if (!IsMainDomainOrAlternative(host)) { if (Program.data.Project.AlternativeDomains.Select(S => host.Contains(S.ToString())).Count() == 0) { string[] arrDom = host.Split(new char[] { '.' }); if (arrDom.Count() > 1) { string auxFinalDom = arrDom[arrDom.Length - 2] + "." + arrDom[arrDom.Length - 1]; Program.data.Project.AlternativeDomains.Add(auxFinalDom); MessageBox.Show("IP address associated to " + Program.data.Project.Domain + " belongs to a Netrange of " + auxFinalDom + ". It is going to be added as an alternative domain.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } } } } catch (Exception) { } if (IsMainDomainOrAlternative(host)) { var netrange = Project.GetNetrange(ip); if (netrange != null) { Project.LstNetRange.Add(netrange); #if PLUGINS Thread tPluginOnNetrange = new Thread(new ParameterizedThreadStart(Program.data.plugins.OnNewNetrange)); tPluginOnNetrange.IsBackground = true; object[] oNetRange = new object[] { new object[] { netrange.from, netrange.to } }; tPluginOnNetrange.Start(oNetRange); #endif if (!Program.cfgCurrent.ScanNetranges255 || Project.GetIpsOfNetrange(netrange) <= 255) { List <string> lstIps = netrange.GenerateIpsOfNetrange(); Program.LogThis(new Log(Log.ModuleType.IPRangeSearch, "Netrange with " + lstIps.Count.ToString() + " IPs", Log.LogType.low)); Thread tAddIps = new Thread(new ParameterizedThreadStart(AddIpListAsync)); tAddIps.IsBackground = true; tAddIps.Priority = ThreadPriority.Lowest; tAddIps.Start(lstIps); } } } } } var ipItem = new IPsItem(ip, source); Ips.Items.Add(ipItem); // OnNewIP #if PLUGINS Thread tPluginOnIP = new Thread(new ParameterizedThreadStart(Program.data.plugins.OnNewIP)); tPluginOnIP.IsBackground = true; object[] oIP = new object[] { new object[] { ip } }; tPluginOnIP.Start(oIP); #endif if (MaxRecursion <= 0) { OnChangeEvent(null); return; } List <string> domains; if (doptr) { if (domainSource != null) { if (Program.cfgCurrent.UseAllDns) { domains = new List <string>(); List <string> dnsServers = DNSUtil.GetNSServer(resolver, domainSource, DNSUtil.GetLocalNSServer().First().ToString()); foreach (string dns in dnsServers) { OnLog(null, new EventsThreads.ThreadStringEventArgs(string.Format("Making reverse resolution to IP: {0} Using DNS server: {1}", ip, dns))); foreach (var domain in DNSUtil.GetHostNames(resolver, ip, dns).Where(domain => !domains.Contains(domain))) { domains.Add(domain); } } } else { var dnsserver = DNSUtil.GetNSServer(resolver, domainSource); OnLog(null, new EventsThreads.ThreadStringEventArgs(string.Format("Making reverse resolution to IP: {0} Using DNS server: {1}", ip, dnsserver))); domains = DNSUtil.GetHostNames(resolver, ip, dnsserver); } } else { domains = DNSUtil.GetHostNames(resolver, ip); } foreach (var domain in domains) { AddResolution(domain, ip, string.Format("{0} > DNS reverse resolution [{1}]", GetIpSource(ip), domain), MaxRecursion - 1, Program.cfgCurrent, true); } } OnChangeEvent(null); } }
public static bool isPublicIP(IPsItem IPv4) { return(isPublicIP(IPv4.Ip)); }
public static bool isPrivateIP(IPsItem IPv4) { return(isPrivateIP(IPv4.Ip)); }
public RelationsItem(DomainsItem domain, IPsItem ip, string source) { this.Domain = domain; this.Ip = ip; this.Source = source; }
public ComputerIPsItem(ComputersItem computer, IPsItem ip, string source) { this.Computer = computer; this.Ip = ip; this.Source = source; }