#!/usr/bin/env python
###Import Library###
import os, time
import nmap

###script Name: Ops401challenge42###
###Author: Bubacarr Darboe###
###Date: 12/03/2020###
###Description of purpose: python nmap###
###Declaration of variable###
scanner = nmap.PortScanner()

print("Nmap Automation Tool")
print("--------------------")

ip_addr = input("IP address to scan: ")
print("The IP you entered is: ", ip_addr)
type(ip_addr)

response = input("""\nPlease enter the type of scan you want to run
                1)SYN ACK Scan
                2)UDP Scan
                3)Regular Scan\n""")
print("You have selected option: ", response)

portrange = '1-50'

###Declaration of Functions###

###Main###


# If user's input is 1, perform a SYN/ACK scan
if response == '1':
    print("Nmap Version: ", scanner.nmap_version())
    scanner.scan(ip_addr, portrange, '-v -sS')
    print(scanner.scaninfo())
    # state() tells if target is up or down
    print("Ip Status: ", scanner[ip_addr].state())
    # all_protocols() tells which protocols are enabled like TCP UDP etc
    print("protocols:",scanner[ip_addr].all_protocols())
    print("Open Ports: ", scanner[ip_addr]['tcp'].keys())
    
# If user's input is 2, perform a UDP Scan   
elif response == '2':
    print("Nmap Version: ", scanner.nmap_version())
    scanner.scan(ip_addr, '80, 443', '-v -sU')
    print(scanner.scaninfo())
    # state() tells if target is up or down
    print("Ip Status: ", scanner[ip_addr].state())
    # all_protocols() tells which protocols are enabled like TCP UDP etc
    print("protocols:",scanner[ip_addr].all_protocols())
    print("Open Ports: ", scanner[ip_addr]['udp'].keys())
    
# If user's input is 3, perform a Regular Scan
elif response == '3':
    # Works on default arguments
    scanner.scan(ip_addr)
    print(scanner.scaninfo())
    print("Ip Status: ", scanner[ip_addr].state())
    print(scanner[ip_addr].all_protocols())
    print("Open Ports: ", scanner[ip_addr]['tcp'].keys())
    
else:
    print("Please choose a number from the options above")

###End###
