问题
Currently trying to record a list of outgoing TCP connections and then compare the present list to the previous list in order to see what connections have been established. However, TCPView.exe seems to be of no luck. I am able to run the application with this:
def get_tcp_conns():
process = Popen([r"C:\Users\PC\Downloads\TCPView\Tcpview.exe"], stdout=PIPE, shell=True)
for line in io.TextIOWrapper(proc.stdout, encoding="utf-8"):
print(line) # Do whatever here
However, this is not returning any text. Not for sure where to go with this as I have no idea how to read the TCP information in python
回答1:
should be something like
import subprocess
def get_tcp_conns():
process = subprocess.run("C:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe './C:Users/PC/Downloads/TCPView/Tcpview.exe' ", shell=True, capture_output=True)
print(process.stdout)
来源:https://stackoverflow.com/questions/64638025/how-to-read-output-from-an-application-using-python