Reputation: 329
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
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
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