/// <summary> /// Does the Linux Kernel support SYNPROXY /// </summary> /// <param name="system"></param> /// <returns></returns> public static bool KernelSupported(ISystemFactory system) { String output, error; using (var process = system.StartProcess("uname", "-r")) { ProcessHelper.ReadToEnd(process, out output, out error); if (process.ExitCode != 0) { throw new IpTablesNetException("Unable to execute uname and retreive the kenel version"); } } var regex = new Regex(@"([0-9]+)\.([0-9]+)\.([0-9]+)\-([0-9]+)"); if (regex.IsMatch(output)) { var match = regex.Match(output); var version = new Version(int.Parse(match.Groups[1].Value), int.Parse(match.Groups[2].Value), int.Parse(match.Groups[3].Value), int.Parse(match.Groups[4].Value)); if (version >= new Version(3, 12)) { return(true); } } return(false); }
/// <summary> /// Does the Linux Kernel support SYNPROXY /// </summary> /// <param name="system"></param> /// <returns></returns> public static bool KernelSupported(ISystemFactory system) { String output, error; using (var process = system.StartProcess("uname", "-r")) { ProcessHelper.ReadToEnd(process, out output, out error); if (process.ExitCode != 0) { throw new IpTablesNetException("Unable to execute uname and retreive the kenel version"); } } var regex = new Regex(@"([0-9]+)\.([0-9]+)\.([0-9]+)\-([0-9]+)"); if (regex.IsMatch(output)) { var match = regex.Match(output); var version = new Version(int.Parse(match.Groups[1].Value), int.Parse(match.Groups[2].Value), int.Parse(match.Groups[3].Value), int.Parse(match.Groups[4].Value)); if (version >= new Version(3, 12)) { return true; } } return false; }
private bool ExecuteTransaction() { String output, error; using (ISystemProcess process = _system.StartProcess(BinaryName, "restore")) { if (WriteStrings(_transactionCommands, process.StandardInput)) { process.StandardInput.Flush(); process.StandardInput.Close(); ProcessHelper.ReadToEnd(process, out output, out error); //OK if (process.ExitCode == 0) { return(true); } } else { ProcessHelper.ReadToEnd(process, out output, out error); } } error = error.Trim(); if (error.Length != 0) { throw new IpTablesNetException(String.Format("Failed to execute transaction: {0}", error)); } return(false); }
protected string[] Command(String command, params String[] args) { String cmd = String.Format("{0} {1} {2}", _module, command, String.Join(" ", args)); using (var process = _system.StartProcess("ip", cmd.TrimEnd())) { String output, error; ProcessHelper.ReadToEnd(process, out output, out error); return(new string[] { output.Trim(), error.Trim() }); } }
public NfAcctUsage Get(String name, bool reset = false) { String cmd = "get {0} xml"; if (reset) { cmd += " reset"; } var process = _system.StartProcess("/usr/sbin/nfacct", String.Format(cmd, name)); process.WaitForExit(); var output = process.StandardOutput.ReadToEnd(); if (output.Trim().Length == 0) { return(null); } return(FromXml(output, name)); }
public String ExecuteBash(String code, out String error) { var process = _system.StartProcess("bash", "-"); process.StandardInput.WriteLine(code); process.StandardInput.Close(); process.WaitForExit(); var output = process.StandardOutput.ReadToEnd(); error = process.StandardError.ReadToEnd().TrimEnd(new char[] { '\n' }); return(output.TrimEnd(new char[] { '\n' })); }
public NfAcctUsage Get(String name, bool reset = false) { String cmd = "get {0} xml"; if (reset) { cmd += " reset"; } String output, error; using (var process = _system.StartProcess("/usr/sbin/nfacct", String.Format(cmd, name))) { ProcessHelper.ReadToEnd(process, out output, out error); } if (output.Trim().Length == 0) { return(null); } return(FromXml(output, name)); }
private bool ExecuteTransaction() { //ipset save ISystemProcess process = _system.StartProcess(BinaryName, "restore"); if (WriteStrings(_transactionCommands, process.StandardInput)) { process.StandardInput.Flush(); process.StandardInput.Close(); process.WaitForExit(); //OK if (process.ExitCode != 0) { return(true); } } return(false); }