CompTIA Pentest+ for Dummies Chapter 10 Prep Test Flashcards

1
Q
You are scripting in Python and would like to check to see if your variable equals the value 192.168.2.2. 
What operator would you use?
A. =
B. ==
C. -eq
D. !=
A

B. ==

Explanation:
Python uses the double equals (==) as the comparison operator to check if a variable is equal to a value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q
You are using an if statement in Bash shell scripting and want to check to see if the $port is less than 1024.
What operator would you use?
A.<
B.<<
C.!=
D.-lt
A

D.-lt

Explanation:
Bash shell scripting uses -lt as the less than comparison operator

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q
WHat statement in Ruby would you use to create a variable and store an IP address in the variable?
(A) $ ip = “192.168.2.100” 
(B) $ ip = = “192.168.2.100” 
(C) _ip = “192.168.2.100” 
(D) _ip = = “192.168.2.100”
A

(C) _ip = “192.168.2.100”

Explanation:
Ruby variables can start with an _ or a lowercase character

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q
You wish to display the third element of an array called "computers" on the screen using Python.
What command would you use?
A. print (computers[4])
B. echo (computers[3])
C.puts )computers[4])
D.write-host (computers[3])
A

A. print (computers[4])

Explanation:
You can print to the screen in Python using the print statement.
In order to access the third element of an array, you would reference index number 4

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q
How do you end an if statement in Bash shell scripting?
A.end
B.fi
C.}
D.end if
A

B.fi

Explanation:
In Bash shell scripting, an if statement ends with the keyword fi

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

You wish to prompt for an IP address in your Python script, what command would you use?
A.$ ipaddress = gets(‘ Please enter IP address of system to scan:’)
B.ipaddress = = input(‘ Please enter IP address of system to scan:’)
C. ipaddress = input(‘ Please enter IP address of system to scan:’)
D. ipaddress = read-host “Please enter IP address of system to scan”

A

C. ipaddress = input(‘ Please enter IP address of system to scan:’)

Explanation:

To prompt for input from the user in Python, you use the input function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q
IN Bash scripting, you would like to append information to a file, how would you do this?
A.>
B.>>
C.out
D.put
A

B.»

Explanation:
In Bash scripting, you can append information to a file using the double redirect (»).
If you want to overwrite the file you would use the single redirect (>)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q
What keyword in Ruby is used to catch exceptions?
A.catch
B.except
C.exception
D.rescue
A

D.rescue

Explanation:
To catch exceptions in Ruby, you use the rescue keyword

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What syntax in PowerShell would you use to read the content of a file into a variable?
(A) $ content = get-content systems.txt
(B) content = $( < systems.txt)
(C) content = open(‘ systems.txt’,’ w’)
(D) content = read-file systems.txt

A

(A) $ content = get-content systems.txt

Explanation:
To read the contents of a file into a variable in PowerShell, you can use the get-content cmdlet

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q
You are creating a script in Ruby and wish to output information on the screen. What command would you use? 
(A) gets 
(B) puts 
(C) write 
(D) out
A

(B) puts

Explanation:
In Ruby you can print information to the screen with a puts statement

How well did you know this?
1
Not at all
2
3
4
5
Perfectly