Socket programming

hI can you please show me how to push my codes to GitHub from Pycharm.
Second I can’t get success getting my socket programming right. 3. I need a Python script to determine which ports are open and display the information in a tidy format. Where port 22 is shown as open display the word “SSH” where port 80 is shown as open display the word “HTTP” on my VM.

any help is great.

hI can you please show me how to push my codes to GitHub from Pycharm.

Alas, I am not a PyCharm user. But please post separate questions in
separate posts. That way they can each have good subject lines.

Second I can’t get success getting my socket programming right. 3. I
need a Python script to determine which ports are open and display the
information in a tidy format. Where port 22 is shown as open display
the word “SSH” where port 80 is shown as open display the word “HTTP”
on my VM.

We do like to see what code you have tried, as this sounds like a
homework or tutorial question. We won’t provide direct solutions but
will offer advice and criticise what you’re doing.

In Python I’d use the subprocess module to run the “netstat” command and
parse its output.

Cheers,
Cameron Simpson cs@cskk.id.au

hi Cameron,

please can you tell me what is the post name where I can ask these questions.

I have posted the screenshot. 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…

many thanks from Ireland

Looks like you’ve created a function (port_scan()). I can’t see from what you’ve posted what exactly you are running, and if this calls that function or not. If you are trying to invoke this file directly, it doesn’t run the function itself, so there would be no output.

Hi

Thank you for your reply, following Is my question.

I
need a Python script to determine which ports are open and display the
information in a tidy format. Where port 22 is shown as open display
the word “SSH” where port 80 is shown as open display the word “HTTP”
on my VM.

regards

many thanks

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