Tony M
Tony M

Reputation: 329

How to run netstat -nb in python

I need to run netstat -nb via python code but everything I tried gives me the same output, "The requested operation requires elevation."

How do I evaluate netstat -nb in python?

Upvotes: 0

Views: 4398

Answers (2)

Baurin Leza
Baurin Leza

Reputation: 2104

other approach with os module:

import os
output_command = os.popen("netstat -nb").readlines()

The argument -b is only for windows and the error message mean that you need administrator permissions.

Upvotes: 1

Prayson W. Daniel
Prayson W. Daniel

Reputation: 15568

Have you tried:

from subprocess import Popen, PIPE

p = Popen(['netstat', 'nb'], stdout=PIPE, stderr=PIPE)

stdout, stderr = p.communicate()
print(stdout)

Upvotes: 0

Related Questions