示例#1
0
        public override IpAddresses DetectDNS()
        {
            IpAddresses list = new IpAddresses();

            // Method1: Don't return DHCP DNS
            string networksetupPath = LocateExecutable("networksetup");

            if (networksetupPath != "")
            {
                string[] interfaces = GetInterfaces();
                foreach (string i in interfaces)
                {
                    string i2 = i.Trim();

                    string current = SystemShell.Shell(networksetupPath, new string[] { "-getdnsservers", SystemShell.EscapeInsideQuote(i2) });

                    foreach (string line in current.Split('\n'))
                    {
                        string field = line.Trim();
                        list.Add(field);
                    }
                }
            }

            // Method2 - More info about DHCP DNS
            string scutilPath = LocateExecutable("scutil");

            if (scutilPath != "")
            {
                string scutilOut             = SystemShell.Shell1(scutilPath, "--dns");
                List <List <string> > result = UtilsString.RegExMatchMulti(scutilOut.Replace(" ", ""), "nameserver\\[[0-9]+\\]:([0-9:\\.]+)");
                foreach (List <string> match in result)
                {
                    foreach (string field in match)
                    {
                        list.Add(field);
                    }
                }
            }

            // Method3 - Compatibility
            if (FileExists("/etc/resolv.conf"))
            {
                string o = FileContentsReadText("/etc/resolv.conf");
                foreach (string line in o.Split('\n'))
                {
                    if (line.Trim().StartsWith("#"))
                    {
                        continue;
                    }
                    if (line.Trim().StartsWith("nameserver"))
                    {
                        string field = line.Substring(11).Trim();
                        list.Add(field);
                    }
                }
            }

            return(list);
        }
示例#2
0
        public override IpAddresses ResolveDNS(string host)
        {
            IpAddresses result = new IpAddresses();

            string getentPath = LocateExecutable("getent");

            if (getentPath != "")
            {
                // Note: CNAME record are automatically followed.
                SystemShell s = new SystemShell();
                s.Path = getentPath;
                s.Arguments.Add("ahosts");
                s.Arguments.Add(SystemShell.EscapeHost(host));
                s.NoDebugLog = true;
                if (s.Run())
                {
                    string o = s.Output;
                    o = o.CleanSpace();
                    foreach (string line in o.Split('\n'))
                    {
                        string[] fields = line.Split(' ');
                        if (fields.Length < 2)
                        {
                            continue;
                        }
                        if (fields[1].Trim() != "STREAM")
                        {
                            continue;
                        }
                        result.Add(fields[0].Trim());
                    }
                }
            }
            return(result);
        }
示例#3
0
        public override bool OnDnsSwitchDo(IpAddresses dns)
        {
            string mode = Engine.Instance.Storage.GetLower("dns.mode");

            if (mode == "auto")
            {
                string[] interfaces = GetInterfaces();
                foreach (string i in interfaces)
                {
                    string i2 = i.Trim();

                    string currentStr = SystemShell.Shell("/usr/sbin/networksetup", new string[] { "-getdnsservers", SystemShell.EscapeInsideQuote(i2) });

                    // v2
                    IpAddresses current = new IpAddresses();
                    foreach (string line in currentStr.Split('\n'))
                    {
                        string ip = line.Trim();
                        if (IpAddress.IsIP(ip))
                        {
                            current.Add(ip);
                        }
                    }

                    if (dns.Equals(current) == false)
                    {
                        DnsSwitchEntry e = new DnsSwitchEntry();
                        e.Name = i2;
                        e.Dns  = current.Addresses;
                        m_listDnsSwitch.Add(e);

                        SystemShell s = new SystemShell();
                        s.Path = LocateExecutable("networksetup");
                        s.Arguments.Add("-setdnsservers");
                        s.Arguments.Add(SystemShell.EscapeInsideQuote(i2));
                        if (dns.IPs.Count == 0)
                        {
                            s.Arguments.Add("empty");
                        }
                        else
                        {
                            foreach (IpAddress ip in dns.IPs)
                            {
                                s.Arguments.Add(ip.Address);
                            }
                        }
                        s.Run();

                        Engine.Instance.Logs.Log(LogType.Verbose, MessagesFormatter.Format(Messages.NetworkAdapterDnsDone, i2, ((current.Count == 0) ? "Automatic" : current.Addresses), dns.Addresses));
                    }
                }

                Recovery.Save();
            }

            base.OnDnsSwitchDo(dns);

            return(true);
        }
示例#4
0
        private void FillCollection_Button_OnClick(object sender, RoutedEventArgs e)
        {

            for (int i = 0; i < 10; i++)
            {
                IpAddresses.Add(new Address("8.8.8.8","Google"));
            }
        }
示例#5
0
        /// <summary>
        /// Specify the IPAddress of the entitled machine
        /// </summary>
        /// <param name="address">IP Address of the machine to run the entitled application(s).</param>
        /// <returns>A new entitlement</returns>
        public NodeEntitlements AddIpAddress(IPAddress address)
        {
            if (address == null)
            {
                throw new ArgumentNullException(nameof(address));
            }

            return(new NodeEntitlements(this, addresses: IpAddresses.Add(address)));
        }
示例#6
0
        private void ScannerOnVlcHostFound(object sender, string s)
        {
            if (ComputerAdapter.Computers.Any(i => i.Ip == s))
            {
                return;
            }

            IpAddresses.Add(new ComputerModel(s));
            RunOnUiThread(() => ComputerAdapter.NotifyDataSetChanged());
        }
示例#7
0
        public override IpAddresses ResolveDNS(string host)
        {
            // Base method with Dns.GetHostEntry have cache issue, for example on Fedora. OS X it's based on Mono.
            // Also, base methods with Dns.GetHostEntry sometime don't fetch AAAA IPv6 addresses.

            IpAddresses result = new IpAddresses();

            string hostPath = LocateExecutable("host");

            if (hostPath != "")
            {
                // Note: CNAME record are automatically followed.
                SystemShell s = new SystemShell();
                s.Path = "/usr/bin/host";
                s.Arguments.Add("-W 5");
                s.Arguments.Add(SystemShell.EscapeHost(host));
                s.NoDebugLog = true;
                if (s.Run())
                {
                    string hostout = s.Output;
                    foreach (string line in hostout.Split('\n'))
                    {
                        string ipv4 = Utils.RegExMatchOne(line, "^.*? has address (.*?)$");
                        if (ipv4 != "")
                        {
                            result.Add(ipv4.Trim());
                        }

                        string ipv6 = Utils.RegExMatchOne(line, "^.*? has IPv6 address (.*?)$");
                        if (ipv6 != "")
                        {
                            result.Add(ipv6.Trim());
                        }
                    }
                }
            }

            return(result);
        }
示例#8
0
        public bool DoVote(int voteId, string ipAddr)
        {
            bool alreadyVoted = alreadyVoted = CheckIfAlreadyVotedToday(ipAddr);

            if (!alreadyVoted)
            {
                Answers[voteId].Votes++;
                IpAddresses.Add(new IpAddressItem(ipAddr, DateTime.Now));
                Save();
            }
            else
            {
                SaveIfModified();
            }
            return(!alreadyVoted);
        }
示例#9
0
        public override IpAddresses GetNetworkLockAllowedIps()
        {
            IpAddresses result = base.GetNetworkLockAllowedIps();

            // Hosts
            XmlNodeList nodesUrls = Storage.DocumentElement.SelectNodes("//urls/url");

            foreach (XmlNode nodeUrl in nodesUrls)
            {
                string url  = nodeUrl.Attributes["address"].Value;
                string host = Utils.HostFromUrl(url);
                result.Add(host);
            }

            return(result);
        }
示例#10
0
        public override IpAddresses GetNetworkLockAllowedIps()
        {
            IpAddresses result = base.GetNetworkLockAllowedIps();

            List <string> urls = GetBootstrapUrls();

            foreach (string url in urls)
            {
                string host = UtilsCore.HostFromUrl(url);
                if (host != "")
                {
                    result.Add(host);
                }
            }

            return(result);
        }
示例#11
0
        private void ParseXML(XDocument pollXml)
        {
            Answers.Clear();
            IpAddresses.Clear();

            Question = pollXml.Element("poll").Element("question").Attribute("text").Value;
            foreach (var answer in pollXml.Element("poll").Elements("answer"))
            {
                Answers.Add(new AnswerItem(answer.Attribute("text").Value, int.Parse(answer.Value)));
            }
            foreach (var ipaddr in pollXml.Element("poll").Elements("ipaddr"))
            {
                IpAddresses.Add(new IpAddressItem(ipaddr.Value,
                                                  DateTime.ParseExact(ipaddr.Attribute("dateEntered").Value,
                                                                      "yyyy/MM/dd HH:mm",
                                                                      CultureInfo.InvariantCulture)));
            }
        }
示例#12
0
        private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrWhiteSpace(Ip_TextBox.Text) || string.IsNullOrWhiteSpace(Name_TextBox.Text))
            {
                MessageBox.Show("IP-адрес и наименование должны быть заполнены!", "Ошибка!", MessageBoxButton.OK);
                return;
            }

            var parse = DataInteract.IsIp(Ip_TextBox.Text);
            if (!parse)
            {
                MessageBox.Show("Проверьте правильность ввода IP адреса!");
                return;
            }

            IpAddresses.Add(new Address(Ip_TextBox.Text, Name_TextBox.Text));
            Ip_TextBox.Clear();
            Name_TextBox.Clear();
        }
示例#13
0
        public IpAddresses DiscoverExit()
        {
            IpAddresses result = new IpAddresses();

            string[] layers = new string[] { "4", "6" };

            foreach (string layer in layers)
            {
                Json jDoc = DiscoverIpData("", layer);
                if ((jDoc != null) && (jDoc.HasKey("ip")))
                {
                    string ip = (jDoc["ip"].Value as string).Trim().ToLowerInvariant();

                    result.Add(ip);
                }
            }

            return(result);
        }
示例#14
0
        public override bool OnDnsSwitchRestore()
        {
            foreach (DnsSwitchEntry e in m_listDnsSwitch)
            {
                /*
                 * string v = e.Dns;
                 * if (v == "")
                 *      v = "empty";
                 * v = v.Replace(",", "\" \"");
                 *
                 * SystemShell.Shell("/usr/sbin/networksetup", new string[] { "-setdnsservers", SystemShell.EscapeInsideQuote(e.Name), v });
                 */
                IpAddresses dns = new IpAddresses();
                dns.Add(e.Dns);

                SystemShell s = new SystemShell();
                s.Path = LocateExecutable("networksetup");
                s.Arguments.Add("-setdnsservers");
                s.Arguments.Add(SystemShell.EscapeInsideQuote(e.Name));
                if (dns.Count == 0)
                {
                    s.Arguments.Add("empty");
                }
                else
                {
                    foreach (IpAddress ip in dns.IPs)
                    {
                        s.Arguments.Add(ip.Address);
                    }
                }
                s.Run();

                Engine.Instance.Logs.Log(LogType.Verbose, MessagesFormatter.Format(Messages.NetworkAdapterDnsRestored, e.Name, ((e.Dns == "") ? "Automatic" : e.Dns)));
            }

            m_listDnsSwitch.Clear();

            Recovery.Save();

            base.OnDnsSwitchRestore();

            return(true);
        }
示例#15
0
        public override bool OnDnsSwitchRestore()
        {
            foreach (DnsSwitchEntry e in m_listDnsSwitch)
            {
                IpAddresses dns = new IpAddresses();
                dns.Add(e.Dns);

                string result = Engine.Instance.Elevated.DoCommandSync("dns-switch-restore", "interface", e.Name, "dns", dns.ToString());

                Engine.Instance.Logs.Log(LogType.Verbose, LanguageManager.GetText("OsMacNetworkAdapterDnsRestored", e.Name, ((e.Dns == "") ? "Automatic" : e.Dns)));
            }

            m_listDnsSwitch.Clear();

            Recovery.Save();

            base.OnDnsSwitchRestore();

            return(true);
        }
示例#16
0
        public override IpAddresses DetectDNS()
        {
            IpAddresses list = new IpAddresses();

            if (FileExists("/etc/resolv.conf"))
            {
                string o = FileContentsReadText("/etc/resolv.conf");
                foreach (string line in o.Split('\n'))
                {
                    if (line.Trim().StartsWith("#", StringComparison.InvariantCulture))
                    {
                        continue;
                    }
                    if (line.Trim().StartsWith("nameserver", StringComparison.InvariantCulture))
                    {
                        list.Add(line.Substring(11).Trim());
                    }
                }
            }
            return(list);
        }
示例#17
0
        public override IpAddresses DetectDNS()
        {
            IpAddresses list = new IpAddresses();

            string networksetupPath = LocateExecutable("networksetup");

            if (networksetupPath != "")
            {
                string[] interfaces = GetInterfaces();
                foreach (string i in interfaces)
                {
                    string i2 = i.Trim();

                    string current = SystemShell.Shell(networksetupPath, new string[] { "-getdnsservers", SystemShell.EscapeInsideQuote(i2) });

                    list.Add(current);
                }
            }

            return(list);
        }
示例#18
0
        public IpAddresses DiscoverExit()
        {
            IpAddresses result = new IpAddresses();

            string[] methods           = Engine.Instance.Storage.Get("discover.ip_webservice.list").Split(';');
            bool     onlyFirstResponse = Engine.Instance.Storage.GetBool("discover.ip_webservice.first");

            string[] layers = new string[] { "4", "6" };

            foreach (string layer in layers)
            {
                XmlDocument xmlDoc = DiscoverIpData("", layer);
                if (xmlDoc != null)
                {
                    string ip = Utils.XmlGetBody(xmlDoc.DocumentElement.SelectSingleNode(".//ip") as XmlElement).ToLowerInvariant().Trim();

                    result.Add(ip);
                }
            }

            return(result);
        }
示例#19
0
        private void AddComputerButtonOnClick(object sender, EventArgs eventArgs)
        {
            var dialogBuilder = new MaterialDialog.Builder(this)
                                .Title(Resource.String.app_addcomputer_title)
                                .CustomView(Resource.Layout.dialog_addcomputer, true)
                                .PositiveText(Resource.String.app_addcomputer_connect)
                                .NegativeText(Resource.String.app_addcomputer_cancel)
                                .OnPositive((dialog, w) =>
            {
                IpAddresses.Add(new ComputerModel(
                                    dialog.CustomView.FindViewById <EditText>(Resource.Id.ipAddress).Text,
                                    dialog.CustomView.FindViewById <EditText>(Resource.Id.password).Text));
                BlobCache.UserAccount.InsertObject("ipaddresses", IpAddresses);
            }).Build();

            var positiveAction = dialogBuilder.GetActionButton(DialogAction.Positive);
            var ipControl      = dialogBuilder.CustomView.FindViewById <EditText>(Resource.Id.ipAddress);
            var token          = new CancellationTokenSource();

            positiveAction.Enabled = false;

            ipControl.TextChanged += (o, args) =>
            {
                token.Cancel();
                token = new CancellationTokenSource();
                if (ValidateIPv4(ipControl.Text) && IpAddresses.All(i => i.Ip != ipControl.Text))
                {
                    Task.Factory.StartNew(
                        async() => positiveAction.Enabled = await Scanner.CheckHostForVlc(ipControl.Text),
                        token.Token);
                }
                else
                {
                    positiveAction.Enabled = false;
                }
            };

            dialogBuilder.Show();
        }
示例#20
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="itemType"></param>
        /// <param name="value"></param>
        private void AddItem(ItemType itemType, object value)
        {
            if (value.ToString().Length == 0)
            {
                return;
            }

            switch (itemType)
            {
            case ItemType.IpAddress:
                var ipAddresses = from ipAddress in IpAddresses where ipAddress.Text.ToUpper() == ((string)value).ToUpper() select ipAddress;
                if (ipAddresses.Count() == 0)
                {
                    IpAddress ipAddress = new IpAddress();
                    ipAddress.Text = (string)value;
                    IpAddresses.Add(ipAddress);
                }
                break;

            case ItemType.HostName:
                var hosts = from host in HostNames where host.ToUpper() == ((string)value).ToUpper() select host;
                if (hosts.Count() == 0)
                {
                    HostNames.Add((string)value);
                }
                break;

            case ItemType.Port:
                var ports = from port in Ports where port == (int)value select port;
                if (ports.Count() == 0)
                {
                    Ports.Add((int)value);
                }
                break;

            case ItemType.Protocol:
                var protocols = from protocol in Protocols where protocol.ToUpper() == ((string)value).ToUpper() select protocol;
                if (protocols.Count() == 0)
                {
                    Protocols.Add(((string)value).ToUpper());
                }
                break;

            case ItemType.Service:
                var services = from service in Services where service.ToUpper() == ((string)value).ToUpper() select service;
                if (services.Count() == 0)
                {
                    Services.Add((string)value);
                }
                break;

            case ItemType.State:
                var states = from state in States where state.ToUpper() == ((string)value).ToUpper() select state;
                if (states.Count() == 0)
                {
                    States.Add((string)value);
                }
                break;

            case ItemType.Severities:
                var severities = from severity in Severities where severity.ToUpper() == ((string)value).ToUpper() select severity;
                if (severities.Count() == 0)
                {
                    Severities.Add((string)value);
                }
                break;

            case ItemType.PluginFamily:
                var pluginFamilies = from pluginFamily in PluginFamilys where pluginFamily.ToUpper() == ((string)value).ToUpper() select pluginFamily;
                if (pluginFamilies.Count() == 0)
                {
                    PluginFamilys.Add((string)value);
                }
                break;

            case ItemType.PluginId:
                var pluginIds = from pluginId in PluginIds where pluginId.ToString().ToUpper() == ((string)value).ToUpper() select pluginId;
                if (pluginIds.Count() == 0)
                {
                    PluginIds.Add(int.Parse(value.ToString()));
                }
                break;

            case ItemType.PluginName:
                var pluginNames = from pluginName in PluginNames where pluginName.ToUpper() == ((string)value).ToUpper() select pluginName;
                if (pluginNames.Count() == 0)
                {
                    PluginNames.Add((string)value);
                }
                break;

            case ItemType.Product:
                var products = from product in Products where product.ToUpper() == ((string)value).ToUpper() select product;
                if (products.Count() == 0)
                {
                    Products.Add((string)value);
                }
                break;

            case ItemType.Versions:
                var versions = from version in Versions where version.ToUpper() == ((string)value).ToUpper() select version;
                if (versions.Count() == 0)
                {
                    Versions.Add((string)value);
                }
                break;

            case ItemType.ExploitAvailable:
                var exploitAvailable = from e in ExploitAvailable where e.ToUpper() == ((string)value).ToUpper() select e;
                if (exploitAvailable.Count() == 0)
                {
                    ExploitAvailable.Add((string)value);
                }
                break;

            default:
                break;
            }
        }