Search code examples
c#ubuntuxamarinmonomonodevelop

C# Monodevelop List all IP addresses connected to your Server on port Ubuntu


I need to get IP addresses witch connected to my server on port on Ubuntu (for exmp: 5809). For example in Ubuntu we have terminal command like this:

netstat -tn 2>/dev/null | grep :5809 | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -nr | head

Output results after this command:

  • 97 114.198.236.100
  • 56 67.166.157.194
  • 44 170.248.43.76
  • 38 141.0.9.20
  • 37 49.248.0.2

How to realize analog of this function in C# Mono Ubuntu ? I hope for your help..


Solution

  • tezaurismosis - answered me in another forum, i'l thanks him.

    var proc = new Process {
        StartInfo = new ProcessStartInfo {
            FileName = @"netstat -tn 2>/dev/null | grep :80| awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -nr | head",
            UseShellExecute = false,
            RedirectStandardOutput = true,
            CreateNoWindow = true
        }
    };
    
    proc.Start();
    while (!proc.StandardOutput.EndOfStream) {
        // каждая строка вывода
        string line = proc.StandardOutput.ReadLine();
    }