/// <summary> /// Process Network nodes. /// </summary> private static void NodeNetworkProcess() { if (Program.data == null) { return; } TreeNode tnPCServers = Program.FormMainInstance.TreeView.GetNode(Navigation.Project.Network.ToNavigationPath()); int nServers = 0; if (tnPCServers != null) { List <ComputersItem> lst = new List <ComputersItem>(Program.data.computers.Items); foreach (ComputersItem computer in lst) { System.Windows.Forms.Application.DoEvents(); TreeNode tn = null; switch (computer.type) { case ComputersItem.Tipo.ClientPC: { tn = tnPCServers.Nodes[Navigation.Project.Network.Clients.Key].Nodes[computer.name]; if (tn == null) { int insertAtIndex = Program.FormMainInstance.SearchTextInNodes(tnPCServers.Nodes[Navigation.Project.Network.Clients.Key].Nodes, computer.name); tn = tnPCServers.Nodes[Navigation.Project.Network.Clients.Key].Nodes.Insert(insertAtIndex, computer.name, computer.name); tn.ContextMenuStrip = Program.FormMainInstance.contextMenu; } else { tn.ContextMenuStrip = Program.FormMainInstance.contextMenu; } } break; case ComputersItem.Tipo.Server: { //Si no tiene una IP asociada añadir al nodo de servidores desconocidos if (!Program.data.computerIPs.Items.Any(C => C.Computer.name == computer.name)) { TreeNode unknownServers = tnPCServers.Nodes[Navigation.Project.Network.Servers.Key].Nodes[Navigation.Project.Network.Servers.Unknown.Key]; if (unknownServers.Nodes[computer.name] != null) { tn = unknownServers.Nodes[computer.name]; } else { int insertAtIndex = Program.FormMainInstance.SearchTextInNodes(unknownServers.Nodes, computer.name); tn = unknownServers.Nodes.Insert(insertAtIndex, computer.name, computer.name); tn.ContextMenuStrip = Program.FormMainInstance.contextMenu; } } else //Como tiene una IP asociada insertar en su rango { string strIP = Program.data.computerIPs.Items.First(C => C.Computer.name == computer.name).Ip.Ip; if (Program.data.Project.IsIpInNetrange(strIP) == false) { continue; } bool found = false; foreach (RelationsItem relation in Program.data.relations.Items.Where(S => S.Ip.Ip == strIP)) { if (relation.Domain.Domain.Contains(Program.data.Project.Domain)) { found = true; break; } foreach (string auxDom in Program.data.Project.AlternativeDomains) { if (relation.Domain.Domain.Contains(auxDom)) { found = true; break; } } } if (!found && DNSUtil.IsIPv4(strIP)) { if (Program.data.IsIpInLimitRange(strIP)) { found = true; } } if (!found) { continue; } //Comprobar que existe el rango if (DNSUtil.IsIPv4(strIP)) { byte[] IPBytes = DNSUtil.IPToByte(strIP); int indexFirstSegment = -1; //IPAddress class A if (IPBytes[0] >= 1 && IPBytes[0] < 128) { indexFirstSegment = 0; } //IPAddress class B else if (IPBytes[0] >= 128 && IPBytes[0] < 192) { indexFirstSegment = 1; } //IPAddress class C else if (IPBytes[0] >= 192 && IPBytes[0] < 240) { indexFirstSegment = 2; } else { return; } tn = GenerateIPRangesNodes(IPBytes, tnPCServers.Nodes[Navigation.Project.Network.Servers.Key], indexFirstSegment); nServers++; } else { //ipv6 } } } break; } if (tn == null) { return; } tn.Text = computer.name; tn.Tag = computer; if (computer.os != OperatingSystem.OS.Unknown) { tn.ImageIndex = tn.SelectedImageIndex = OperatingSystemUtils.OSToIconNumber(computer.os); } else { tn.ImageIndex = tn.SelectedImageIndex = computer.type == ComputersItem.Tipo.ClientPC ? 111 : 45; } foreach (ComputerDomainsItem cdi in Program.data.computerDomains.Items) { if (cdi.Domain == null) { continue; } if (cdi.Computer == computer) { if (!tn.Nodes.ContainsKey(cdi.Domain.Domain)) { TreeNode newTn = new TreeNode(cdi.Domain.Domain); newTn.Text = cdi.Domain.Domain; newTn.Name = cdi.Domain.Domain; newTn.Tag = cdi; if (cdi.Domain.os == OperatingSystem.OS.Unknown) { newTn.SelectedImageIndex = newTn.ImageIndex = 90; } else { newTn.SelectedImageIndex = newTn.ImageIndex = OperatingSystemUtils.OSToIconNumber(cdi.Domain.os); } tn.Nodes.Add(newTn); } } TreeNode oldTn = tn.Nodes[cdi.Domain.Domain]; if (oldTn == null) { continue; } oldTn.ImageIndex = OperatingSystemUtils.OSToIconNumber(cdi.Domain.os); oldTn.SelectedImageIndex = oldTn.ImageIndex; OperatingSystem.OS lastOsDom = OperatingSystem.OS.Unknown; bool networkDevice = false; foreach (ComputerDomainsItem cdiDom in from TreeNode tnDom in tn.Nodes where tnDom.Tag is ComputerDomainsItem select(ComputerDomainsItem) tnDom.Tag) { if ((cdiDom.Domain.os != lastOsDom) && (cdiDom.Domain.os != OperatingSystem.OS.Unknown) && (lastOsDom != OperatingSystem.OS.Unknown)) { networkDevice = true; break; } if (cdiDom.Domain.os != OperatingSystem.OS.Unknown) { lastOsDom = cdiDom.Domain.os; } } if (networkDevice) { tn.ImageIndex = tn.SelectedImageIndex = 100; } else if (lastOsDom != OperatingSystem.OS.Unknown) { tn.ImageIndex = tn.SelectedImageIndex = OperatingSystemUtils.OSToIconNumber(lastOsDom); } } if (computer.Users.Items.Count > 0) { TreeNode tnUsers; if (tn.Nodes["Users"] == null) { tnUsers = tn.Nodes.Add("Users", "Users"); tnUsers.ImageIndex = tnUsers.SelectedImageIndex = 14; } else { tnUsers = tn.Nodes["Users"]; } tnUsers.Tag = computer.Users; } else if (tn.Nodes["Users"] != null) { tn.Nodes["Users"].Remove(); } if (computer.Description.Items.Count > 0) { TreeNode tnDescription; if (tn.Nodes["Description"] == null) { tnDescription = tn.Nodes.Add("Description", "Description"); } else { tnDescription = tn.Nodes["Description"]; } tnDescription.Tag = computer.Description; } else if (tn.Nodes["Description"] != null) { tn.Nodes["Description"].Remove(); } if (computer.RemotePasswords.Items.Count > 0) { TreeNode tnPasswords; if (tn.Nodes["Passwords"] == null) { tnPasswords = tn.Nodes.Add("Passwords", "Passwords"); tnPasswords.ImageIndex = tnPasswords.SelectedImageIndex = 121; } else { tnPasswords = tn.Nodes["Passwords"]; } tnPasswords.Tag = computer.RemotePasswords; } else if (tn.Nodes["Passwords"] != null) { tn.Nodes["Passwords"].Remove(); } if (computer.Folders.Items.Count > 0) { TreeNode tnFolders; if (tn.Nodes["Folders"] == null) { tnFolders = tn.Nodes.Add("Folders", "Folders"); tnFolders.ImageIndex = tnFolders.SelectedImageIndex = 117; } else { tnFolders = tn.Nodes["Folders"]; } tnFolders.Tag = computer.Folders; } else if (tn.Nodes["Folders"] != null) { tn.Nodes["Folders"].Remove(); } if (computer.Printers.Items.Count > 0) { TreeNode tnPrinters; if (tn.Nodes["Printers"] == null) { tnPrinters = tn.Nodes.Add("Printers", "Printers"); tnPrinters.ImageIndex = tnPrinters.SelectedImageIndex = 118; } else { tnPrinters = tn.Nodes["Printers"]; } tnPrinters.Tag = computer.Printers; } else if (tn.Nodes["Printers"] != null) { tn.Nodes["Printers"].Remove(); } if (computer.RemoteUsers.Items.Count > 0) { TreeNode tnRemoteUsers; if (tn.Nodes["Users with access"] == null) { tnRemoteUsers = tn.Nodes.Add("Users with access", "Users with access"); tnRemoteUsers.ImageIndex = tnRemoteUsers.SelectedImageIndex = 43; } else { tnRemoteUsers = tn.Nodes["Users with access"]; } tnRemoteUsers.Tag = computer.RemoteUsers; } else if (tn.Nodes["Users with access"] != null) { tn.Nodes["Users with access"].Remove(); } if (computer.RemoteFolders.Items.Count > 0) { TreeNode tnRemoteFolders; if (tn.Nodes["Remote Folders"] == null) { tnRemoteFolders = tn.Nodes.Add("Remote Folders", "Remote Folders"); tnRemoteFolders.ImageIndex = tnRemoteFolders.SelectedImageIndex = 42; } else { tnRemoteFolders = tn.Nodes["Remote Folders"]; } tnRemoteFolders.Tag = computer.RemoteFolders; } else if (tn.Nodes["Remote Folders"] != null) { tn.Nodes["Remote Folders"].Remove(); } if (computer.RemotePrinters.Items.Count > 0) { TreeNode tnRemotePrinters; if (tn.Nodes["Remote Printers"] == null) { tnRemotePrinters = tn.Nodes.Add("Remote Printers", "Remote Printers"); tnRemotePrinters.ImageIndex = tnRemotePrinters.SelectedImageIndex = 44; } else { tnRemotePrinters = tn.Nodes["Remote Printers"]; } tnRemotePrinters.Tag = computer.RemotePrinters; } else if (tn.Nodes["Remote Printers"] != null) { tn.Nodes["Remote Printers"].Remove(); } } } if (tnPCServers != null) { for (int i = tnPCServers.Nodes["Clients"].Nodes.Count; i > 0; i--) { TreeNode tn = tnPCServers.Nodes["Clients"].Nodes[i - 1]; if (!Program.data.computers.Items.Any(C => C.type == ComputersItem.Tipo.ClientPC && C.name.ToLower() == tn.Text.ToLower())) { tn.Remove(); } } Program.FormMainInstance.DeleteNodesServers(tnPCServers.Nodes["Servers"].Nodes); tnPCServers.Nodes["Clients"].Text = string.Format("Clients ({0})", tnPCServers.Nodes["Clients"].Nodes.Count); tnPCServers.Nodes["Servers"].Text = string.Format("Servers ({0})", nServers); } }
/// <summary> /// Process Network nodes. /// </summary> static private void NodeNetworkProcess() { if (Program.data == null) { return; } var nServers = 0; var tnPCServers = Program.FormMainInstance.TreeView.Nodes[TreeViewKeys.KProject.ToString()].Nodes[TreeViewKeys.KPCServers.ToString()]; if (tnPCServers != null) { var lst = new ThreadSafeList <ComputersItem>(Program.data.computers.Items); foreach (var computer in lst) { Application.DoEvents(); TreeNode tn = null; switch (computer.type) { case ComputersItem.Tipo.ClientPC: { tn = tnPCServers.Nodes["Clients"].Nodes[computer.name]; if (tn == null) { var insertAtIndex = Program.FormMainInstance.SearchTextInNodes(tnPCServers.Nodes["Clients"].Nodes, computer.name); tn = tnPCServers.Nodes["Clients"].Nodes.Insert(insertAtIndex, computer.name, computer.name); tn.ContextMenuStrip = Program.FormMainInstance.contextMenu; } else { tn.ContextMenuStrip = Program.FormMainInstance.contextMenu; } } break; case ComputersItem.Tipo.Server: { //Si no tiene una IP asociada añadir al nodo de servidores desconocidos if (!Program.data.computerIPs.Items.Any(C => C.Computer.name == computer.name)) { Object x = Program.FormMainInstance.TreeView; if (tnPCServers.Nodes["Servers"].Nodes["Unknown Servers"].Nodes[computer.name] != null) { tn = tnPCServers.Nodes["Servers"].Nodes["Unknown Servers"].Nodes[computer.name]; } else { int insertAtIndex = Program.FormMainInstance.SearchTextInNodes(tnPCServers.Nodes["Servers"].Nodes["Unknown Servers"].Nodes, computer.name); tn = tnPCServers.Nodes["Servers"].Nodes["Unknown Servers"].Nodes.Insert(insertAtIndex, computer.name, computer.name); tn.ContextMenuStrip = Program.FormMainInstance.contextMenu; } if (tn == null) { return; } } else //Como tiene una IP asociada insertar en su rango { string strIP = Program.data.computerIPs.Items.First(C => C.Computer.name == computer.name).Ip.Ip; if (Program.data.Project.IsIpInNetrange(strIP) == false) { continue; } bool found = false; foreach (RelationsItem relation in Program.data.relations.Items.Where(S => S.Ip.Ip == strIP)) { if (relation.Domain.Domain.Contains(Program.data.Project.Domain) == true) { found = true; } foreach (string auxDom in Program.data.Project.AlternativeDomains) { if (relation.Domain.Domain.Contains(auxDom)) { found = true; } } } if ((found == false) && (DNSUtil.IsIPv4(strIP))) { if (Program.data.IsIpInLimitRange(strIP)) { found = true; } } if (found == false) { continue; } //Comprobar que existe el rango if (DNSUtil.IsIPv4(strIP)) { byte[] IPBytes = DNSUtil.IPToByte(strIP); //Dependiendo de la calse de Ip que sea tiene que dibujarla a una profundidad u otra //IP de clase A if (IPBytes[0] >= 1 && IPBytes[0] < 128) { TreeNode tnIP = null; string iprange = string.Format("{0}.0.0.0", IPBytes[0]); if (tnPCServers.Nodes["Servers"].Nodes[iprange] != null) { tnIP = tnPCServers.Nodes["Servers"].Nodes[iprange]; } else { tnIP = tnPCServers.Nodes["Servers"].Nodes.Insert(Program.FormMainInstance.SearchTextInNodes(tnPCServers.Nodes["Servers"].Nodes, iprange), iprange, iprange); tnIP.ContextMenuStrip = Program.FormMainInstance.contextMenu; tnIP.ImageIndex = tnIP.SelectedImageIndex = 18; tnIP.Tag = "iprange"; } if (tnIP == null) { return; } iprange = string.Format("{0}.{1}.0.0", IPBytes[0], IPBytes[1]); if (tnIP.Nodes[iprange] != null) { tnIP = tnIP.Nodes[iprange]; } else { tnIP = tnIP.Nodes.Insert(Program.FormMainInstance.SearchTextInNodes(tnIP.Nodes, iprange), iprange, iprange); tnIP.ContextMenuStrip = Program.FormMainInstance.contextMenu; tnIP.ImageIndex = tnIP.SelectedImageIndex = 18; tnIP.Tag = "iprange"; } if (tnIP == null) { return; } iprange = string.Format("{0}.{1}.{2}.0", IPBytes[0], IPBytes[1], IPBytes[2]); if (tnIP.Nodes[iprange] != null) { tnIP = tnIP.Nodes[iprange]; } else { tnIP = tnIP.Nodes.Insert(Program.FormMainInstance.SearchTextInNodes(tnIP.Nodes, iprange), iprange, iprange); tnIP.ContextMenuStrip = Program.FormMainInstance.contextMenu; tnIP.ImageIndex = tnIP.SelectedImageIndex = 18; tnIP.Tag = "iprange"; } iprange = string.Format("{0}.{1}.{2}.{3}", IPBytes[0], IPBytes[1], IPBytes[2], IPBytes[3]); if (tnIP.Nodes[iprange] != null) { tn = tnIP.Nodes[iprange]; } else { tn = tnIP.Nodes.Insert(Program.FormMainInstance.SearchTextInNodes(tnIP.Nodes, iprange), iprange, computer.name); tn.ContextMenuStrip = Program.FormMainInstance.contextMenu; } if (tn == null) { return; } } //IP de clase B else if (IPBytes[0] >= 128 && IPBytes[0] < 192) { TreeNode tnIP = null; string iprange = string.Format("{0}.{1}.0.0", IPBytes[0], IPBytes[1]); if (tnPCServers.Nodes["Servers"].Nodes[iprange] != null) { tnIP = tnPCServers.Nodes["Servers"].Nodes[iprange]; } else { tnIP = tnPCServers.Nodes["Servers"].Nodes.Insert(Program.FormMainInstance.SearchTextInNodes(tnPCServers.Nodes["Servers"].Nodes, iprange), iprange, iprange); tnIP.ContextMenuStrip = Program.FormMainInstance.contextMenu; tnIP.ImageIndex = tnIP.SelectedImageIndex = 18; tnIP.Tag = "iprange"; } if (tnIP == null) { return; } iprange = string.Format("{0}.{1}.{2}.0", IPBytes[0], IPBytes[1], IPBytes[2]); if (tnIP.Nodes[iprange] != null) { tnIP = tnIP.Nodes[iprange]; } else { tnIP = tnIP.Nodes.Insert(Program.FormMainInstance.SearchTextInNodes(tnIP.Nodes, iprange), iprange, iprange); tnIP.ContextMenuStrip = Program.FormMainInstance.contextMenu; tnIP.ImageIndex = tnIP.SelectedImageIndex = 18; tnIP.Tag = "iprange"; } iprange = string.Format("{0}.{1}.{2}.{3}", IPBytes[0], IPBytes[1], IPBytes[2], IPBytes[3]); if (tnIP.Nodes[iprange] != null) { tn = tnIP.Nodes[iprange]; } else { tn = tnIP.Nodes.Insert(Program.FormMainInstance.SearchTextInNodes(tnIP.Nodes, iprange), iprange, computer.name); tn.ContextMenuStrip = Program.FormMainInstance.contextMenu; } } //IP de clase C else if (IPBytes[0] >= 192 && IPBytes[0] < 240) { TreeNode tnIP = null; string iprange = string.Format("{0}.{1}.{2}.0", IPBytes[0], IPBytes[1], IPBytes[2]); if (tnPCServers.Nodes["Servers"].Nodes[iprange] != null) { tnIP = tnPCServers.Nodes["Servers"].Nodes[iprange]; } else { tnIP = tnPCServers.Nodes["Servers"].Nodes.Insert(Program.FormMainInstance.SearchTextInNodes(tnPCServers.Nodes["Servers"].Nodes, iprange), iprange, iprange); tnIP.ContextMenuStrip = Program.FormMainInstance.contextMenu; tnIP.ImageIndex = tnIP.SelectedImageIndex = 18; tnIP.Tag = "iprange"; } if (tnIP == null) { return; } iprange = string.Format("{0}.{1}.{2}.{3}", IPBytes[0], IPBytes[1], IPBytes[2], IPBytes[3]); if (tnIP.Nodes[iprange] != null) { tn = tnIP.Nodes[iprange]; } else { tn = tnIP.Nodes.Insert(Program.FormMainInstance.SearchTextInNodes(tnIP.Nodes, iprange), iprange, computer.name); tn.ContextMenuStrip = Program.FormMainInstance.contextMenu; } } nServers++; } else { //ipv6 } } } break; } Program.FormMainInstance.TreeView.Invoke(new MethodInvoker(delegate { if (tn == null) { return; } tn.Tag = computer; if (computer.os != OperatingSystem.OS.Unknown) { tn.ImageIndex = tn.SelectedImageIndex = OperatingSystemUtils.OSToIconNumber(computer.os); } else { tn.ImageIndex = tn.SelectedImageIndex = computer.type == ComputersItem.Tipo.ClientPC ? 111 : 45; } var computersDomain = Program.data.computerDomains.Items; foreach (var cdi in computersDomain.Where(x => x.Computer == computer)) { if (cdi.Domain == null) { continue; } if (!(tn.Nodes.ContainsKey(cdi.Domain.Domain))) { var newTn = new TreeNode(cdi.Domain.Domain); newTn.Text = cdi.Domain.Domain; newTn.Name = cdi.Domain.Domain; newTn.Tag = cdi; if (cdi.Domain.os == OperatingSystem.OS.Unknown) { newTn.SelectedImageIndex = newTn.ImageIndex = 90; } else { newTn.SelectedImageIndex = newTn.ImageIndex = OperatingSystemUtils.OSToIconNumber(cdi.Domain.os); } tn.Nodes.Add(newTn); } } foreach (var cdi in Program.data.computerDomains.Items) { if (cdi.Domain == null) { return; } var oldTn = tn.Nodes[cdi.Domain.Domain]; if (oldTn == null) { continue; } if (cdi.Domain == null) { continue; } oldTn.ImageIndex = OperatingSystemUtils.OSToIconNumber(cdi.Domain.os); oldTn.SelectedImageIndex = oldTn.ImageIndex; OperatingSystem.OS lastOsDom = OperatingSystem.OS.Unknown; var networkDevice = false; lastOsDom = OperatingSystem.OS.Unknown; foreach (ComputerDomainsItem cdiDom in from TreeNode tnDom in tn.Nodes where tnDom.Tag is ComputerDomainsItem select(ComputerDomainsItem) tnDom.Tag) { if ((cdiDom.Domain.os != lastOsDom) && (cdiDom.Domain.os != OperatingSystem.OS.Unknown) && (lastOsDom != OperatingSystem.OS.Unknown)) { networkDevice = true; break; } if (cdiDom.Domain.os != OperatingSystem.OS.Unknown) { lastOsDom = cdiDom.Domain.os; } } if (networkDevice) { tn.ImageIndex = tn.SelectedImageIndex = 100; } else if (lastOsDom != OperatingSystem.OS.Unknown) { tn.ImageIndex = tn.SelectedImageIndex = OperatingSystemUtils.OSToIconNumber(lastOsDom); } } if (computer.Users.Items.Count > 0) { TreeNode tnUsers; if (tn.Nodes["Users"] == null) { tnUsers = tn.Nodes.Add("Users", "Users"); tnUsers.ImageIndex = tnUsers.SelectedImageIndex = 14; } else { tnUsers = tn.Nodes["Users"]; } tnUsers.Tag = computer.Users; } else if (tn.Nodes["Users"] != null) { tn.Nodes["Users"].Remove(); } if (computer.Description.Items.Count > 0) { TreeNode tnDescription; if (tn.Nodes["Description"] == null) { tnDescription = tn.Nodes.Add("Description", "Description"); } else { tnDescription = tn.Nodes["Description"]; } tnDescription.Tag = computer.Description; } else if (tn.Nodes["Description"] != null) { tn.Nodes["Description"].Remove(); } if (computer.RemotePasswords.Items.Count > 0) { TreeNode tnPasswords; if (tn.Nodes["Passwords"] == null) { tnPasswords = tn.Nodes.Add("Passwords", "Passwords"); tnPasswords.ImageIndex = tnPasswords.SelectedImageIndex = 121; } else { tnPasswords = tn.Nodes["Passwords"]; } tnPasswords.Tag = computer.RemotePasswords; } else if (tn.Nodes["Passwords"] != null) { tn.Nodes["Passwords"].Remove(); } if (computer.Folders.Items.Count > 0) { TreeNode tnFolders; if (tn.Nodes["Folders"] == null) { tnFolders = tn.Nodes.Add("Folders", "Folders"); tnFolders.ImageIndex = tnFolders.SelectedImageIndex = 117; } else { tnFolders = tn.Nodes["Folders"]; } tnFolders.Tag = computer.Folders; } else if (tn.Nodes["Folders"] != null) { tn.Nodes["Folders"].Remove(); } if (computer.Printers.Items.Count > 0) { TreeNode tnPrinters; if (tn.Nodes["Printers"] == null) { tnPrinters = tn.Nodes.Add("Printers", "Printers"); tnPrinters.ImageIndex = tnPrinters.SelectedImageIndex = 118; } else { tnPrinters = tn.Nodes["Printers"]; } tnPrinters.Tag = computer.Printers; } else if (tn.Nodes["Printers"] != null) { tn.Nodes["Printers"].Remove(); } if (computer.RemoteUsers.Items.Count > 0) { TreeNode tnRemoteUsers; if (tn.Nodes["Users with access"] == null) { tnRemoteUsers = tn.Nodes.Add("Users with access", "Users with access"); tnRemoteUsers.ImageIndex = tnRemoteUsers.SelectedImageIndex = 43; } else { tnRemoteUsers = tn.Nodes["Users with access"]; } tnRemoteUsers.Tag = computer.RemoteUsers; } else if (tn.Nodes["Users with access"] != null) { tn.Nodes["Users with access"].Remove(); } if (computer.RemoteFolders.Items.Count > 0) { TreeNode tnRemoteFolders; if (tn.Nodes["Remote Folders"] == null) { tnRemoteFolders = tn.Nodes.Add("Remote Folders", "Remote Folders"); tnRemoteFolders.ImageIndex = tnRemoteFolders.SelectedImageIndex = 42; } else { tnRemoteFolders = tn.Nodes["Remote Folders"]; } tnRemoteFolders.Tag = computer.RemoteFolders; } else if (tn.Nodes["Remote Folders"] != null) { tn.Nodes["Remote Folders"].Remove(); } if (computer.RemotePrinters.Items.Count > 0) { TreeNode tnRemotePrinters; if (tn.Nodes["Remote Printers"] == null) { tnRemotePrinters = tn.Nodes.Add("Remote Printers", "Remote Printers"); tnRemotePrinters.ImageIndex = tnRemotePrinters.SelectedImageIndex = 44; } else { tnRemotePrinters = tn.Nodes["Remote Printers"]; } tnRemotePrinters.Tag = computer.RemotePrinters; } else if (tn.Nodes["Remote Printers"] != null) { tn.Nodes["Remote Printers"].Remove(); } })); } } if (tnPCServers != null) { for (var i = tnPCServers.Nodes["Clients"].Nodes.Count; i > 0; i--) { var tn = tnPCServers.Nodes["Clients"].Nodes[i - 1]; if (!Program.data.computers.Items.Any(C => C.type == ComputersItem.Tipo.ClientPC && C.name.ToLower() == tn.Text.ToLower())) { Program.FormMainInstance.TreeView.Invoke(new MethodInvoker(delegate { tn.Remove(); })); } } Program.FormMainInstance.DeleteNodesServers(tnPCServers.Nodes["Servers"].Nodes); Program.FormMainInstance.TreeView.Invoke(new MethodInvoker(delegate { tnPCServers.Nodes["Clients"].Text = string.Format("Clients ({0})", tnPCServers.Nodes["Clients"].Nodes.Count); })); tnPCServers.Nodes["Servers"].Text = string.Format("Servers ({0})", nServers); } }
/// <summary> /// /// </summary> public void GetServersFromIPs() { var lstDomains = new List <string>(); if (!string.IsNullOrEmpty(Project.Domain)) { lstDomains.Add(Project.Domain); } lstDomains.AddRange(Project.AlternativeDomains); var lstIPs = new ThreadSafeList <IPsItem>(Ips.Items.Where(IP => Project.Domain == "*" || relations.Items.Any(R => R.Ip.Ip == IP.Ip && lstDomains.Any(D => R.Domain.Domain.ToLower().EndsWith(D.ToLower()))))); var po = new ParallelOptions(); if (Program.cfgCurrent.ParallelDnsQueries != 0) { po.MaxDegreeOfParallelism = Program.cfgCurrent.ParallelDnsQueries; } Parallel.ForEach(lstIPs, ip => { try { ComputersItem ci; if (computerIPs.Items.Any(C => C.Ip.Ip == ip.Ip)) { ci = computerIPs.Items.First(C => C.Ip.Ip == ip.Ip).Computer; } else { if (computers.Items.Any(C => relations.Items.Where(R => R.Ip.Ip == ip.Ip).Select(D => D.Domain).Any(D => string.Equals(D.Domain, C.name, StringComparison.OrdinalIgnoreCase)))) { ci = computers.Items.First(C => relations.Items.Where(R => R.Ip.Ip == ip.Ip).Select(D => D.Domain).Any(D => string.Equals(D.Domain, C.name, StringComparison.OrdinalIgnoreCase))); ci.name = string.Format("{0} [{1}]", ci.name, ip.Ip); computerIPs.Items.Add(new ComputerIPsItem(ci, ip, ip.Source)); } else { ci = new ComputersItem(); computers.Items.Add(ci); ci.type = ComputersItem.Tipo.Server; ci.os = OperatingSystem.OS.Unknown; var strFirstDomain = string.Empty; try { strFirstDomain = relations.Items.First(R => R.Ip.Ip == ip.Ip && lstDomains.Any(D => R.Domain.Domain.ToLower().EndsWith(D.ToLower()))).Domain.Domain; } catch { strFirstDomain = "*"; } ci.name = string.Format("{0} [{1}]", strFirstDomain, ip.Ip); computerIPs.Items.Add(new ComputerIPsItem(ci, ip, ip.Source)); } } foreach (DomainsItem di in relations.Items.Where(R => R.Ip.Ip == ip.Ip).Select(D => D.Domain)) { if (!computerDomains.Items.Any(C => C.Computer.name == ci.name && C.Domain.Domain == di.Domain)) { computerDomains.Items.Add(new ComputerDomainsItem(ci, di, di.Source)); } for (var fpI = 0; fpI < di.fingerPrinting.Count(); fpI++) { var fp = di.fingerPrinting[fpI]; if ((fp.os != OperatingSystem.OS.Unknown)) { ci.os = fp.os; } foreach (var software in BannerAnalysis.GetSoftwareFromBanner(fp.Version).Where(software => !ci.Software.Items.Any(A => A.Name.ToLower() == software.ToLower()))) { ci.Software.Items.Add(new ApplicationsItem(software, string.Format("{0} FingerPrinting Banner: {1}", di.Domain, fp.Version))); } } } if (ip.Information != null) { if (!string.IsNullOrEmpty(ip.Information.OS)) { var os = OperatingSystemUtils.StringToOS(ip.Information.OS); if (ci.os == OperatingSystem.OS.Unknown && os != OperatingSystem.OS.Unknown) { ci.os = os; } } if (!string.IsNullOrEmpty(ip.Information.ServerBanner)) { var os = OperatingSystemUtils.StringToOS(ip.Information.ServerBanner); if (ci.os == OperatingSystem.OS.Unknown && os != OperatingSystem.OS.Unknown) { ci.os = os; } foreach (var software in BannerAnalysis.GetSoftwareFromBanner(ip.Information.ServerBanner).Where(software => !ci.Software.Items.Any(A => A.Name.ToLower() == software.ToLower()))) { ci.Software.Items.Add(new ApplicationsItem(software, string.Format("{0} Shodan Banner: {1}", ip, ip.Information.ServerBanner))); } } } } catch { } }); OnChangeEvent(null); }