socket.connect question about parenthesis - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Networking (https://python-forum.io/forum-12.html) +--- Thread: socket.connect question about parenthesis (/thread-32201.html) |
socket.connect question about parenthesis - pace - Jan-27-2021 Hi everyone, I have been starting out with python over the past 8 months. I know I'm just at the start of my journey, and this is the first programming language that I have been working with. I am currently playing around with socket. My question is simple, why do I need double parenthesis sock.connect((ipaddress, port)), to get my program to work? import socket #from IPy import IP ipaddress = input("Enter target to scan: ") port = 80 #Esablish a connection to a port using socket try: sock = socket.socket() sock.connect((ipaddress, port)) print("[+] Port 80 is open: ") except: print("[-] Port 80 is closed: ") RE: socket.connect question about parenthesis - Gribouillis - Jan-30-2021 The answer is simple, the method socket.connect.connect() takes a single argument, the address where the socket should connect. For a socket of the AF_INET family type (the default), the address is a tuple with two elements (host, port) . So you are not using double parentheses, you are passing a single argument which is a tuple.
|