please can you tell me what is the post name where I can ask these
questions.
I do not know what you mean here.
I have posted the screenshot.
Please just copy/paste text from your IDE into a new message. Those of
us on email do not see screenshots, and must visit, tediously, the web
forum to look at them, and we cannot ourselves copy the text to try it
out, or to quote it in replies. Vision impaired users will also have
trouble with screenshots.
The result is marked 0, but I can see the port 80 or 22 and nor its
showing what is the protocols on these ports…
BowlOfRed has remarked that you define a function. Maybe it is unclear,
but although you define the function, nothing calls it. So running your
script defines a function. And finishes successfully, having done
nothing else.
You need to call the function:
port_scan()
at the bottom of the script.
Other remarks: you seem to call “cls”, probably to clear the screen.
Personally I find programmes which erase the existing display very
annoying. You’re calling it with shell=true. The true constant in Python
is spelled “True” with a capital “T”.
Please do not use shell=True, it opens you programme up to injection
issues because you are constructing a shell command. Instead, pass an
explicit argument list:
subprocess.call(["cls"])
See that that is a list containing one string? To run netstat you will
want:
subprocess.call(["netstat", "-a"])
Also, since you will need to parse the output of netstat, you will want:
subprocess.call(["netstat", "-a"], stdout=subprocess.PIPE)
There is a subprocess.communicate() function in the subprocess module
which will serve you better here: it can run a command and collect the
output for you to work with. See the subprocess documentation here:
https://docs.python.org/3/library/subprocess.html#subprocess.Popen.communicate
Cheers,
Cameron Simpson cs@cskk.id.au