Check which processes are connected to the internet

4

Is it possible to check which processes are connected to the internet and what is your destination?

    
asked by anonymous 25.11.2014 / 19:12

1 answer

3

It does not seem very simple. I have also never tried to do this but found some answers in SO .

It seems the simplest way is to call an external process and run the Windows utility to report this. It would look something like:

var process = new System.Diagnostics.Process { //se usar o using não precisa do namespace
    StartInfo = new ProcessStartInfo {
        StartInfo.FileName = "netstat.exe";
        StartInfo.Arguments = "-abnot";
        StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
        RedirectStandardOutput = true;
    }
}
process.Start();
while (!process.StandardOutput.EndOfStream) {
    var line = process.StandardOutput.ReadLine();
    // faz alguma coisa com o conteúdo de cada linha recebida do processo
}

I placed GitHub for future reference .

There is also the alternative of using P / Invoke and creating an API access with GetExtendedTcpTable() . But I do not know how to do it.

I found an answer in the SO that shows you how to do at least basic access (I do not know if that works for you). Yeah, it's not that simple.

    
25.11.2014 / 19:27