public void Start(IpAddress address) { if (address.Valid) { m_address = address; if (Engine.Instance.NetworkLockManager != null) Engine.Instance.NetworkLockManager.AllowIP(m_address); } else { } }
public void ReadXML(XmlElement node) { Address = node.GetAttribute("address"); Mask = node.GetAttribute("mask"); Gateway = node.GetAttribute("gateway"); Interface = node.GetAttribute("interface"); Metrics = node.GetAttribute("metrics"); Flags = node.GetAttribute("flags"); Mss = node.GetAttribute("mss"); Window = node.GetAttribute("window"); Irtt = node.GetAttribute("irtt"); RefCount = 1; }
public static string ToKey(IpAddress address, IpAddress mask) { return address.Value + "-" + mask.Value; }
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); }
public virtual void DeallowIP(IpAddress ip) { }
public bool Contains(IpAddress ip) { return(IPs.Contains(ip)); }
public bool Contains(IpAddress ip) { return(m_hashset.Contains(ip)); }
public static string ToKey(IpAddress address, IpAddress mask) { return(address.Address + "-" + mask.Address); }
public RouteScope(IpAddress address) { Start(address); }
public Json Compute(ConnectionActive connectionActive) { Json jRoute = new Json(); jRoute["address"].Value = Address.ToCIDR(); if (Gateway == "vpn_gateway") { jRoute["interface"].Value = connectionActive.InterfaceId; IpAddresses vpnGateways = connectionActive.OpenVpnProfileWithPush.ExtractGateway(); if (Address.IsV4) { if (vpnGateways.OnlyIPv4.Count == 0) { Engine.Instance.Logs.LogWarning("Unable to compute route for " + Address.ToCIDR() + ": IPv4 VPN gateway not available."); return(null); } else { jRoute["gateway"].Value = vpnGateways.OnlyIPv4.First.Address; } } else if (Address.IsV6) { if (vpnGateways.OnlyIPv6.Count == 0) { Engine.Instance.Logs.LogVerbose("Unable to compute route for " + Address.ToCIDR() + ": IPv6 VPN gateway not available."); return(null); } else { jRoute["gateway"].Value = vpnGateways.OnlyIPv6.First.Address; } } else { return(null); } } else if (Gateway == "net_gateway") { if (Address.IsV4) { IpAddress netGateway = Engine.Instance.GetDefaultGatewayIPv4(); if (netGateway == null) { Engine.Instance.Logs.LogWarning("Unable to compute route for " + Address.ToCIDR() + ": IPv4 Net gateway not available."); return(null); } else { jRoute["gateway"].Value = netGateway.Address; jRoute["interface"].Value = Engine.Instance.GetDefaultInterfaceIPv4(); } } else if (Address.IsV6) { IpAddress netGateway = Engine.Instance.GetDefaultGatewayIPv6(); if (netGateway == null) { Engine.Instance.Logs.LogVerbose("Unable to compute route for " + Address.ToCIDR() + ": IPv6 Net gateway not available."); return(null); } else { jRoute["gateway"].Value = netGateway.Address; jRoute["interface"].Value = Engine.Instance.GetDefaultInterfaceIPv6(); } } else { return(null); } } else { // ClodoTemp: Unsupported on Windows for now, we need the interface. IpAddress ip = new IpAddress(Gateway); if (ip.Valid == false) { Engine.Instance.Logs.LogWarning("Gateway " + Gateway + " invalid."); return(null); } else if ((Address.IsV4) && (ip.IsV6)) { Engine.Instance.Logs.LogWarning("Gateway " + Gateway + " is IPv6 but used for IPv4 address."); return(null); } else if ((Address.IsV6) && (ip.IsV4)) { Engine.Instance.Logs.LogWarning("Gateway " + Gateway + " is IPv4 but used for IPv6 address."); return(null); } else { jRoute["gateway"].Value = ip.Address; } } return(jRoute); }
public virtual void DeallowIP(IpAddress ip) { }
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); }
public void DeallowIP(IpAddress ip) { if (m_current != null) m_current.DeallowIP(ip); }
public RouteScope(IpAddress address) { Start(address); }
public static bool IsIP(string ip) { IpAddress v = new IpAddress(ip); return(v.Valid); }
public override void DeallowIP(IpAddress ip) { base.DeallowIP(ip); }
public override void AllowIP(IpAddress ip) { base.AllowIP(ip); }
public IpAddress(IpAddress value) { m_ip = value.m_ip; m_bitmask = value.m_bitmask; }