import nmap3
def nmap_scan(address,nmapType):
nmap = nmap3.Nmap()
result = f'nmap.{nmapType}({address})'
#result = nmap.nmapType(address) gives the error nmap type is not a member of class nmap
print(result)
nmap_scan(127.0.0.1,scan_top_ports) #user input will be given here
What I want the code to do is take user input on the type of scan he wants from the python-nmap3
repo and use it as a variable in the result = f'nmap.nmapType(address)'
line.
However, if I remove the f string, python
treats nmapType
variable as a method to the class nmap
. What I want is the user to be able to specify the method name in the variable nmapType
.
Is there a way around to solve this problem and use user input to call the correct nmap
method based on user input?
I want the user to enter the scan type, pass that to nmap_scan
function, and use it to perform the scan.