During a security assessment, a penetration tester decides to implement a simple TCP port scanner to check the open ports from 1000 to 2000. Which of the following Python scripts would achieve this task?
A.
fori in range(1000, 2001): s = socket(AF_INET, SOCK_STREAM)
conn = s.connect_ex((host_IP, i))
if (conn == 0):
print(fPort {i} OPEN’)
B.
close ()
C.
fori in range(1001, 2000): s = socket(AF_INET, SOCK_STREAM) conn = s.connect—ex((host_IP, i)) if (conn == 0): print (f'Port {i} OPEN’) s.close ()
D.
fori in range(1000, 2001): s = socket(AF—INET, SOCK_DGRAM) conn = s.connect—ex((host_IP, i)) if (conn == 0): print(f’Port {i} OPEN’) s.close ()
E.
fori in range (1000, 2000): s = socket(SOCK_STREAM, AF_INET) conn = s.connect—ex((host—IP, i)) if (conn == 0): print (f'Port {i} OPEN') s.close()
The correct Python script for implementing a simple TCP port scanner that checks for open ports from 1000 to 2000 is option A. This script uses a for loop to iterate through the range of ports, creates a socket object for each port using the socket.AF_INET address family (indicating IPv4) and socket.SOCK_STREAM socket type (indicating TCP), and attempts to connect to each port. If the connection attempt (connect_ex) returns 0, it indicates the port is open, and the script prints a message stating that the port is open before closing the socket. The other options contain syntax errors, use incorrect socket types, or have incorrect ranges that do not fully cover the specified ports.
Contribute your Thoughts:
Chosen Answer:
This is a voting comment (?). You can switch to a simple comment. It is better to Upvote an existing comment if you don't have anything to add.
Submit