Valid PT0-002 Dumps shared by ExamDiscuss.com for Helping Passing PT0-002 Exam! ExamDiscuss.com now offer the newest PT0-002 exam dumps, the ExamDiscuss.com PT0-002 exam questions have been updated and answers have been corrected get the newest ExamDiscuss.com PT0-002 dumps with Test Engine here:
A penetration tester developed the following script to be used during an engagement: #!/usr/bin/python import socket, sys ports = [21, 22, 23, 25, 80, 139, 443, 445, 3306, 3389] if len(sys.argv) > 1: target = socket.gethostbyname (sys. argv [0]) else: print ("Few arguments.") print ("Syntax: python {} <target ip>". format (sys. argv [0])) sys.exit () try: for port in ports: s = socket. socket (socket. AF_INET, socket. SOCK_STREAM) s.settimeout (2) result = s.connect_ex ((target, port) ) if result == 0: print ("Port {} is opened". format (port) ) except KeyboardInterrupt: print ("\nExiting ... ") sys.exit () However, when the penetration tester ran the script, the tester received the following message: socket.gaierror: [Errno -2] Name or service not known Which of the following changes should the penetration tester implement to fix the script?
Correct Answer: A
The socket.gaierror: [Errno -2] Name or service not known is an error that occurs when the socket module cannot resolve the hostname or IP address given as an argument. In this case, the script is using sys.argv[0] as the argument for socket.gethostbyname, which is the name of the script itself, not the target IP address. The target IP address should be the first command-line argument after the script name, which is sys.argv1. Therefore, changing the script to use sys.argv1 as the argument for socket.gethostbyname will fix the error and allow the script to scan the ports of the target IP address. Reference: * The Official CompTIA PenTest+ Study Guide (Exam PT0-002), Chapter 5: Attacks and Exploits, page 262-263. * socket.gaierror: [Errno -2] Name or service not known | Python1 * How do I fix the error socket.gaierror: [Errno -2] Name or service not known on debian/testing?2