1

How can python help accept a specific port number from a user as input and return all the ips listening on that port on the system. The python script could be running locally on a linux system where this is needed or may access the linux system remotely using an ip specified and needs to get the ip listening on a particular port say. 9223.

Basically it should be similar to a python implementation of netstat -ln | grep port with port being a user input.

Would appreciate any help in this regard.

codecrazy46
  • 275
  • 1
  • 5
  • 14

1 Answers1

0

I would use the subprocess, to run a command line command like netstat.

import subprocess
print subprocess.check_output(['ls','-lah'])

To listen to ports, with Python code, I would refer to this topic

Listening to port and capturing data in python

Karl Johan Vallner
  • 3,980
  • 4
  • 35
  • 46
  • Thanks but is there a way to get this done without the need to execute linux commands for getting this i.e. to using python socket programming library. – codecrazy46 Dec 31 '18 at 10:03