exam questions

Exam PT0-002 All Questions

View all questions & answers for the PT0-002 exam

Exam PT0-002 topic 1 question 278 discussion

Actual exam question from CompTIA's PT0-002
Question #: 278
Topic #: 1
[All PT0-002 Questions]

A penetration tester developed the following script to be used during an engagement:



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?

  • A.
  • B.
  • C.
  • D.
Show Suggested Answer Hide Answer
Suggested Answer: A 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
Etc_Shadow28000
10 months, 2 weeks ago
Selected Answer: A
The issue in the script is caused by the incorrect usage of sys.argv[0] to retrieve the target IP address. sys.argv[0] contains the name of the script itself, not the arguments passed to it. The correct way to retrieve the first argument (the target IP address) is sys.argv[1]. From: target = socket.gethostbyname(sys.argv[0]) To: target = socket.gethostbyname(sys.argv[1])
upvoted 1 times
...
Tytuss
1 year, 1 month ago
"The error message socket.gaierror: [Errno -2] Name or service not known is typically raised when a hostname cannot be resolved. In this case, the issue lies in this line of the script: target = socket.gethostbyname(sys.argv[0]) Here, sys.argv[0] is being used, which actually refers to the name of the script itself, not the first argument passed to the script. The first argument passed to the script is sys.argv[1]. So, to fix the script, the penetration tester should replace sys.argv[0] with sys.argv[1]. The corrected line should be: target = socket.gethostbyname(sys.argv[1])
upvoted 2 times
...
TiredOfTests
1 year, 6 months ago
Selected Answer: A
A. From: target = socket.gethostbyname(sys.argv[0]) To: target = socket.gethostbyname(sys.argv[1])
upvoted 3 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago