I have a code that should get either a python or bash script and execute it using exec
or subprocess.check_output
.
I cannot edit the original code.
The given code should initiate a session (using requests
or curl
or socket
or telnet
etc..) and I want to know the local port given to this subprocess running the code during the session.
For example:
In [115]: process = subprocess.Popen(['curl', 'www.example.com'])
...: ps = psutil.Process(process.pid)
...: print(ps.connections(), ps.net_connections(), ps.open_files())
...: print(process.pid)
...: process.communicate()
I’d like to know what is the local port created in the session to example.com.
I thought about sniffing packets during the run, but since I’m planning on running concurrent requests it won’t help me differentiate between them.
I’m using macOS, but planning to run this code on an ubuntu VM.
4