exam questions

Exam PT0-002 All Questions

View all questions & answers for the PT0-002 exam

Exam PT0-002 topic 1 question 237 discussion

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

A penetration tester created the following script to use in an engagement:



However, the tester is receiving the following error when trying to run the script:



Which of the following is the reason for the error?

  • A. The sys variable was not defined.
  • B. The argv variable was not defined.
  • C. The sys module was not imported.
  • D. The argv module was not imported.
Show Suggested Answer Hide Answer
Suggested Answer: C 🗳️

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: C
The reason for the error is: C. The sys module was not imported. Explanation: In Python, the sys module provides access to some variables used or maintained by the interpreter and to functions that interact strongly with the interpreter. The script attempts to use sys.argv to get the command-line arguments but encounters a NameError because the sys module has not been imported.
upvoted 2 times
Etc_Shadow28000
10 months, 2 weeks ago
Corrected Script: To fix the error, you need to import the sys module at the beginning of the script. Here is the corrected script: #!/usr/bin/python import socket import sys # Import the sys module ports = [21, 22, 23, 25, 80, 139, 443, 445, 3306, 3389] if len(sys.argv) == 2: target = socket.gethostbyname(sys.argv[1]) else: print("Few arguments.") print("Syntax: python {} <target>".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)) s.close() except KeyboardInterrupt: print("Exiting...") sys.exit()
upvoted 2 times
...
...
0b18240
1 year, 1 month ago
Selected Answer: C
#!/usr/bin/python import socket import sys # Import the sys module ports = [21, 22, 23, 25, 80, 139, 443, 445, 3306, 3389] if len(sys.argv) == 2: target = socket.gethostbyname(sys.argv[1]) print("Few arguments.") print("Syntax: python {} <target>".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 open".format(port)) except KeyboardInterrupt: print("Exiting ... ") sys.exit()
upvoted 1 times
...
[Removed]
2 years, 1 month ago
Selected Answer: C
The error message "NameError: name 'sys' is not defined" suggests that the script is trying to use the sys module, but it hasn't been properly imported or defined. Therefore, option C - "The sys module was not imported" - is the correct answer.
upvoted 1 times
...
dhiller
2 years, 2 months ago
Selected Answer: C
sys module not imported
upvoted 3 times
...
KingIT_ENG
2 years, 2 months ago
C is the answer
upvoted 2 times
...
cy_analyst
2 years, 2 months ago
Selected Answer: C
The script uses the sys module to get the command line arguments. The error message indicates that the interpreter does not recognize the sys name, which suggests that the module was not imported.
upvoted 3 times
cy_analyst
2 years, 2 months ago
#!/usr/bin/python import socket ports = [21,22,23,25,80,139,443,445,3306,3389] if len(sys.argv) == 2: target = socket.gethostbyname(sys.argv[1]) else: print("Few arguments.") print("Syntax: python {} <>".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 Keyboardlnterrupt: print("Exiting...") sys.exit()
upvoted 3 times
...
...
kenechi
2 years, 2 months ago
Selected Answer: C
This error occurs when the sys module is used without importing it first.
upvoted 3 times
kenechi
2 years, 2 months ago
https://bobbyhadz.com/blog/python-nameerror-name-sys-is-not-defined
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