Capturing netcat shell command output in Python
This question already has an answer here:
If you want make calling shell commands easy to yourself in Python use sh library.
In sh this would be:
from sh import nc
output = nc("-v", "192.168.1.1", "25") # output is string of the command output
As always, installing Python libraries are recommended to do with virtualenv.
I use this to capture output from a system command, note that it will only get the last line. Modify around lastline as needed to get more:
def GetOutput(command):
lastline = os.popen(command).readlines()
result = lastline[0].rstrip()
return result
链接地址: http://www.djcxy.com/p/13506.html
上一篇: 将嵌套的bash命令放入Python中