ExamGecko
Question list
Search
Search

List of questions

Search

Related questions











Question 378 - PT0-002 discussion

Report
Export

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.
for i in range(1000, 2001): s = socket(AF_INET, SOCK_STREAM) conn = s.connect_ex((host_IP, i)) if (conn == 0): print(fPort {i} OPEN') s.close ()
Answers
A.
for i in range(1000, 2001): s = socket(AF_INET, SOCK_STREAM) conn = s.connect_ex((host_IP, i)) if (conn == 0): print(fPort {i} OPEN') s.close ()
B.
for i 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 ()
Answers
B.
for i 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 ()
C.
for i 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 ()
Answers
C.
for i 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 ()
D.
for i 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()
Answers
D.
for i 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()
Suggested answer: A

Explanation:

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.

asked 02/10/2024
luis lozano
40 questions
User
Your answer:
0 comments
Sorted by

Leave a comment first