Why does Python's sockets module show a port as closed even though nmap shows it as open?

41 Views Asked by At

I am learning port scanning through a Udemy course.

Afer finding the open port 445 using Nmap:

enter image description here

The video from the course asked us to change the port in the code we created accordingly

enter image description here

And after saving the change, we should execute it with

./[NAME]

In the video, it shows "Port is open". But when I do it, I get "Port is closed" even though Nmap shows it is open:

enter image description here

Am I doing anything wrong?

PS: I keep getting the syntax error even though the code I created is identical to the one in the video.

1

There are 1 best solutions below

0
liam On

replace the line with the print statement with: print(f"port: {port} is closed")