0

I am familiar with python although it's been years since I've used it since I have taken more senior roles where my scripting skills have diminished from non-use. I have received the following error and supplied the code in use below. Grateful for any insight shared.

./portscan1.py

File "/home/kali/pythonprograms/scanning/./portscan1.py", line 12 print "Port %d is closed" % (port) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?



                                
#! /usr/bin/python

import socket

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

host = "10.10.1.23"
port = 443

def portscanner(port):
        if sock.connect_ex((host,port)):
                print "Port %d is closed" % (port)
        else:
                print "Port %d is opened" % (port)

portscanner(port)

I attempted to add parenthesis () as the error output suggested with no luck...

0

1 Answer 1

1

You must add parenthesis like this (for python 3):

print("Port %d is opened" % (port))

Or you can try this:

print("Port {} is opened".format(port))

Or you can also try f string:

print(f"Port {port} is opened")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.