0

Is there any module or easy way to access netstat data using Python script in Linux? I remember that in Perl you could just execute system("netstat -parameters") and save output into array, which isn't cleanest and finest way in my opinion. I wounder if there are any modules in Python which can make it possible to access same data as can be accessed using netstat -ltupn? If "socket" then how to use it?

1 Answers1

0

You could start a subprocess and either wait for the results with communicate.

Example:

command = Popen(['command'], stdin=PIPE, stdout=PIPE, stderr=PIPE) result1,err= command.communicate()

or follow one of the suggestions given in this other question

Community
  • 1
  • 1
Tom
  • 54
  • 4
  • Okay, so with that said, there is no module which can help me to avoid executing commands and saving output? –  Jul 11 '15 at 19:59