Example #1
0
        public static List <string> GetNetworkGateways()
        {
            List <string> list = new List <string>();

            foreach (NetworkInterface f in NetworkInterface.GetAllNetworkInterfaces())
            {
                if (f.OperationalStatus == OperationalStatus.Up)
                {
                    foreach (GatewayIPAddressInformation d in f.GetIPProperties().GatewayAddresses)
                    {
                        string ip = d.Address.ToString();
                        if ((IpAddress.IsIP(ip)) && (ip != "0.0.0.0") && (list.Contains(ip) == false))
                        {
                            list.Add(ip);
                        }
                    }
                }
            }

            return(list);
        }
Example #2
0
        public void DefaultGateways()
        {
            string        t            = "";
            List <string> gatewaysList = new List <string>();

            foreach (NetworkInterface f in NetworkInterface.GetAllNetworkInterfaces())
            {
                if (f.OperationalStatus == OperationalStatus.Up)
                {
                    foreach (GatewayIPAddressInformation d in f.GetIPProperties().GatewayAddresses)
                    {
                        string ip = d.Address.ToString();
                        if ((IpAddress.IsIP(ip)) && (ip != "0.0.0.0") && (gatewaysList.Contains(ip) == false))
                        {
                            //gatewaysList.Add(ip);

                            t += ip + ", " + f.Description + "\n";
                        }
                    }
                }
            }

            Add("Default gateways", t);
        }
Example #3
0
        public static XmlDocument FetchUrls(string title, string authPublicKey, List <string> urls, Dictionary <string, string> parameters)
        {
            parameters["login"]    = Engine.Instance.Storage.Get("login");
            parameters["password"] = Engine.Instance.Storage.Get("password");
            parameters["system"]   = Platform.Instance.GetSystemCode();
            parameters["version"]  = Constants.VersionInt.ToString(CultureInfo.InvariantCulture);

            string firstError = "";
            int    hostN      = 0;

            foreach (string url in urls)
            {
                string host = Utils.HostFromUrl(url);

                hostN++;
                if (IpAddress.IsIP(host) == false)
                {
                    // If locked network are enabled, skip the hostname and try only by IP.
                    // To avoid DNS issue (generally, to avoid losing time).
                    if (Engine.Instance.NetworkLockManager.IsDnsResolutionAvailable(host) == false)
                    {
                        continue;
                    }
                }

                try
                {
                    RouteScope  routeScope = new RouteScope(host);
                    XmlDocument xmlDoc     = AirExchange.FetchUrl(authPublicKey, url, parameters);
                    routeScope.End();
                    if (xmlDoc == null)
                    {
                        throw new Exception("No answer.");
                    }

                    if (xmlDoc.DocumentElement.Attributes["error"] != null)
                    {
                        throw new Exception(xmlDoc.DocumentElement.Attributes["error"].Value);
                    }

                    return(xmlDoc);
                }
                catch (Exception e)
                {
                    string info      = e.Message;
                    string proxyMode = Engine.Instance.Storage.Get("proxy.mode").ToLowerInvariant();
                    string proxyAuth = Engine.Instance.Storage.Get("proxy.auth").ToLowerInvariant();
                    if (proxyMode != "none")
                    {
                        info += " - with '" + proxyMode + "' proxy and '" + proxyAuth + "' auth";
                    }

                    if (Engine.Instance.Storage.GetBool("advanced.expert"))
                    {
                        Engine.Instance.Logs.Log(LogType.Verbose, MessagesFormatter.Format(Messages.ExchangeTryFailed, title, hostN.ToString(), info));
                    }

                    if (firstError == "")
                    {
                        firstError = info;
                    }
                }
            }

            throw new Exception(firstError);
        }
Example #4
0
        public static IpAddresses GetGuardIps(bool force)
        {
            // This is called a lots of time.
            Int64 now = Utils.UnixTimeStamp();

            if ((force == false) && ((now - m_lastGuardTime < 60)))
            {
                return(m_lastGuardIps);
            }

            IpAddresses ips = new IpAddresses();

            try
            {
                string controlHost = Engine.Instance.Storage.Get("proxy.host").ToLowerInvariant().Trim();

                if ((controlHost != "127.0.0.1") && (controlHost.ToLowerInvariant() != "localhost"))
                {
                    // Guard IPS are used to avoid routing loop, that occur only if the Tor host is the same machine when OpenVPN run.
                    return(ips);
                }

                List <string> ipsMessages = new List <string>();

                using (TcpClient s = new TcpClient())
                {
                    Connect(s);

                    Write(s, "getinfo circuit-status\n");
                    Flush(s);
                    string circuits = Read(s);

                    string[] circuitsLines = circuits.Split('\n');
                    foreach (string circuit in circuitsLines)
                    {
                        string id = circuit.ToLowerInvariant().RegExMatchOne("\\d+\\sbuilt\\s\\$([0-9a-f]+)");

                        if (id != "")
                        {
                            Write(s, "getinfo ns/id/" + id.ToUpperInvariant() + "\n");
                            string nodeInfo = Read(s);

                            string[] nodeLines = nodeInfo.Split('\n');
                            foreach (string line in nodeLines)
                            {
                                string ip = line.RegExMatchOne("r\\s.+?\\s.+?\\s.+?\\s.+?\\s.+?\\s(.+?)\\s");

                                if ((IpAddress.IsIP(ip)) && (!ips.Contains(ip)))
                                {
                                    ips.Add(ip);
                                    ipsMessages.Add(ip + " (circuit)");
                                }
                            }
                        }
                    }

                    Write(s, "getconf bridge\n");
                    Flush(s);
                    string bridges = Read(s);

                    if (bridges.IndexOf("meek") == -1)                     //Panic if we have meek enabled, don't yet know what to do :-(
                    {
                        string[] bridgeLines = bridges.Split('\n');
                        foreach (string bridge in bridgeLines)
                        {
                            List <string> matches = bridge.ToLowerInvariant().RegExMatchSingle("250.bridge=(.+?)\\s([0-9a-f\\.\\:]+?):\\d+\\s");
                            if ((matches != null) && (matches.Count == 2))
                            {
                                string bridgeType = matches[0];
                                string ip         = matches[1];

                                if ((IpAddress.IsIP(ip)) && (!ips.Contains(ip)))
                                {
                                    ips.Add(matches[1]);
                                    ipsMessages.Add(matches[1] + " (" + bridgeType + ")");
                                }
                            }
                        }
                    }
                    else
                    {
                        Engine.Instance.Logs.Log(LogType.Warning, LanguageManager.GetText("TorControlMeekUnsupported"));
                    }

                    if (ips.Count == 0)
                    {
                        Engine.Instance.Logs.Log(LogType.Warning, LanguageManager.GetText("TorControlNoIps"));
                        //throw new Exception(Messages.TorControlNoIps);
                    }
                    else
                    {
                        string list = String.Join("; ", ipsMessages.ToArray());
                        Engine.Instance.Logs.Log(LogType.Verbose, LanguageManager.GetText("TorControlGuardIps", list));
                    }
                }
            }
            catch (Exception e)
            {
                //throw new Exception(LanguageManager.GetText("TorControlException, e.Message));
                Engine.Instance.Logs.Log(LogType.Warning, LanguageManager.GetText("TorControlException", e.Message));
            }

            m_lastGuardIps  = ips;
            m_lastGuardTime = now;

            return(ips);
        }
Example #5
0
        public virtual string GenerateSystemReport()
        {
            string t = "";

            t += "Operating System: " + Platform.Instance.VersionDescription() + "\n";
            t += "System font: " + Platform.Instance.GetSystemFont() + "\n";
            t += "System monospace font: " + Platform.Instance.GetSystemFontMonospace() + "\n";

            try
            {
                NetworkInterface[] interfaces = NetworkInterface.GetAllNetworkInterfaces();
                foreach (NetworkInterface adapter in interfaces)
                {
                    t += "Network Interface: " + adapter.Name + " (" + adapter.Description + ", ID:" + adapter.Id.ToString() + ") - " + adapter.NetworkInterfaceType.ToString() + " - " + adapter.OperationalStatus.ToString();
                    //t += " - Down:" + adapter.GetIPv4Statistics().BytesReceived.ToString();
                    //t += " - Up:" + adapter.GetIPv4Statistics().BytesSent.ToString();
                    t += "\n";
                }
            }
            catch (Exception)
            {
                t += "Unable to fetch network interfaces.\n";
            }

            t += "\nRouting:\n";
            try
            {
                List <RouteEntry> routeEntries = RouteList();
                foreach (RouteEntry routeEntry in routeEntries)
                {
                    t += routeEntry.ToString() + "\n";
                }
            }
            catch (Exception)
            {
                t += "Unable to fetch routes.\n";
            }


            t += "\nDefault gateways:\n";
            List <string> gatewaysList = new List <string>();

            foreach (NetworkInterface f in NetworkInterface.GetAllNetworkInterfaces())
            {
                if (f.OperationalStatus == OperationalStatus.Up)
                {
                    foreach (GatewayIPAddressInformation d in f.GetIPProperties().GatewayAddresses)
                    {
                        string ip = d.Address.ToString();
                        if ((IpAddress.IsIP(ip)) && (ip != "0.0.0.0") && (gatewaysList.Contains(ip) == false))
                        {
                            //gatewaysList.Add(ip);

                            t += ip + ", " + f.Description + "\n";
                        }
                    }
                }
            }

            return(t);
        }