public virtual bool OnRouteDefaultRemoveDo() { List <RouteEntry> routeEntries = RouteList(); foreach (RouteEntry routeEntry in routeEntries) { if (routeEntry.Mask.ToString() == "0.0.0.0") { m_routeDefaultRemove = routeEntry; routeEntry.Remove(); Recovery.Save(); } } return(true); }
public virtual void RouteAdd(RouteEntry r) { NotImplemented(); }
public virtual void RouteRemove(RouteEntry r) { NotImplemented(); }
public override List<RouteEntry> RouteList() { List<RouteEntry> entryList = new List<RouteEntry>(); string result = ShellCmd("route -n -ee"); string[] lines = result.Split('\n'); foreach (string line in lines) { string[] fields = Utils.StringCleanSpace(line).Split(' '); if (fields.Length == 11) { RouteEntry e = new RouteEntry(); e.Address = fields[0]; e.Gateway = fields[1]; e.Mask = fields[2]; e.Flags = fields[3].ToUpperInvariant(); e.Metrics = fields[4]; // Ref, Use ignored e.Interface = fields[7]; e.Mss = fields[8]; e.Window = fields[9]; e.Irtt = fields[10]; if (e.Address.Valid == false) continue; if (e.Gateway.Valid == false) continue; if (e.Mask.Valid == false) continue; entryList.Add(e); } } return entryList; }
public override void RouteRemove(RouteEntry r) { string cmd = "route del"; cmd += " -net " + r.Address.Value; cmd += " gw " + r.Gateway.Value; cmd += " netmask " + r.Mask.Value; /* if(r.Metrics != "") cmd += " metric " + r.Metrics; */ if(r.Interface != "") cmd += " dev " + r.Interface; ShellCmd(cmd); }
public override void RouteAdd(RouteEntry r) { string cmd = "route add"; cmd += " -net " + r.Address.Value; cmd += " netmask " + r.Mask.Value; cmd += " gw " + r.Gateway.Value; if(r.Metrics != "") cmd += " metric " + r.Metrics; if( (r.Mss != "") && (r.Mss != "0") ) cmd += " mss " + r.Mss; if( (r.Window != "") && (r.Window != "0") ) cmd += " window " + r.Window; if (r.Irtt != "") cmd += " irtt " + r.Irtt; if (r.Flags.Contains("!")) cmd += " reject"; if (r.Flags.Contains("M")) cmd += " mod"; if (r.Flags.Contains("D")) cmd += " dyn"; if (r.Flags.Contains("R")) cmd += " reinstate"; if(r.Interface != "") cmd += " dev " + r.Interface; ShellCmd(cmd); }
public virtual bool OnRouteDefaultRemoveRestore() { if (m_routeDefaultRemove != null) { m_routeDefaultRemove.Add(); m_routeDefaultRemove = null; Recovery.Save(); } return true; }
public virtual void OnRecoveryLoad(XmlElement root) { XmlElement nodeRouteDefaultRemoved = Utils.XmlGetFirstElementByTagName(root, "RouteDefaultRemoved"); if (nodeRouteDefaultRemoved != null) { m_routeDefaultRemove = new RouteEntry(); m_routeDefaultRemove.ReadXML(nodeRouteDefaultRemoved); } OnRouteDefaultRemoveRestore(); OnDnsSwitchRestore(); OnIpV6Restore(); }
public virtual bool OnRouteDefaultRemoveDo() { List<RouteEntry> routeEntries = RouteList(); foreach (RouteEntry routeEntry in routeEntries) { if (routeEntry.Mask.ToString() == "0.0.0.0") { m_routeDefaultRemove = routeEntry; routeEntry.Remove(); Recovery.Save(); } } return true; }
public override void RouteRemove(RouteEntry r) { string cmd = "route delete " + r.Address.Value + " mask " + r.Mask.Value + " " + r.Gateway.Value; ShellCmd(cmd); }
public override List<RouteEntry> RouteList() { List<RouteEntry> entryList = new List<RouteEntry>(); // 'route print' show IP in Interface fields, but 'route add' need the interface ID. We use a map. Dictionary<string, string> InterfacesIp2Id = new Dictionary<string, string>(); ManagementClass objMC = new ManagementClass("Win32_NetworkAdapterConfiguration"); ManagementObjectCollection objMOC = objMC.GetInstances(); foreach (ManagementObject objMO in objMOC) { if (!((bool)objMO["IPEnabled"])) continue; string[] ips = Conversions.ToString(objMO["IPAddress"]).Trim().Split(','); string id = Conversions.ToString(objMO["InterfaceIndex"]).Trim(); foreach (string ip in ips) { InterfacesIp2Id[ip.Trim()] = id; } } // Loopback interface it's not in the enumeration below. InterfacesIp2Id["127.0.0.1"] = "1"; string cmd = "route PRINT"; string result = ShellCmd(cmd); string[] lines = result.Split('\n'); foreach (string line in lines) { string[] fields = Utils.StringCleanSpace(line).Split(' '); if(fields.Length == 5) { // Route line. RouteEntry e = new RouteEntry(); e.Address = fields[0]; e.Mask = fields[1]; e.Gateway = fields[2]; e.Interface = fields[3]; e.Metrics = fields[4]; if(e.Address.Valid == false) continue; if(e.Mask.Valid == false) continue; if (e.Gateway.Value != "On-link") { if (e.Gateway.Valid == false) continue; } if (InterfacesIp2Id.ContainsKey(e.Interface)) { e.Interface = InterfacesIp2Id[e.Interface]; entryList.Add(e); } else { Engine.Instance.Logs.LogDebug("Unexpected."); } } } return entryList; }
public override void RouteAdd(RouteEntry r) { string cmd = ""; cmd += "route add " + r.Address.Value + " mask " + r.Mask.Value + " " + r.Gateway.Value; /* * Metric param are ignored or misinterpreted. http://serverfault.com/questions/238695/how-can-i-set-the-metric-of-a-manually-added-route-on-windows if(r.Metrics != "") cmd += " metric " + r.Metrics; */ if (r.Interface != "") cmd += " if " + r.Interface; ShellCmd(cmd); }
public override void RouteRemove(RouteEntry r) { base.RouteRemove (r); }
public override void RouteAdd(RouteEntry r) { base.RouteAdd (r); }