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); }
/// <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.FirstOrDefault(x => x.Ip == ip); if (res == null) { res = new IPsItem("", ""); } } catch { res = new IPsItem("", ""); } return(res); }
public RelationsItem(DomainsItem domain, IPsItem ip, string source) : base() { this.Domain = domain; this.Ip = ip; this.Ip.IdProject = Program.data.Project.Id; this.Source = source; }
/// <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); Program.LogThis(new Log(Log.ModuleType.FOCA, "IP address associated to " + Program.data.Project.Domain + " belongs to a Netrange of " + auxFinalDom + ". It is going to be added as an alternative domain.", Log.LogType.low)); } } } } } } 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 ComputerIPsItem(ComputersItem computer, IPsItem ip, string source) : base() { this.Computer = computer; this.Ip = ip; this.Source = source; }