import nmap
import argparse


def nmap_scan(tgt_host, tgt_ports):
    nm_scan = nmap.PortScanner()
    for port in tgt_ports:
        nm_scan.scan(tgt_host, port)
        state = nm_scan[tgt_host]['tcp'][int(port)]['state']
        print(f'[*] {tgt_host} tcp/{port} {state}')


if __name__ == '__main__':
    parser = argparse.ArgumentParser(usage='nmap_scan.py TARGET_HOST -p TARGET_PORTS'
                                     '\nexample: python3 nmap_scan.py scanme.nmap.org -p 21,80')

    parser.add_argument('host', type=str, metavar='TARGET_HOST',
                        help="specify target host's IP address")
    parser.add_argument('-p', required=True, type=str, metavar='TARGET_PORTS',
                        help='specify target port[s] separated by comma (no space)')

    args = parser.parse_args()

    args.ports = str(args.p).split(',')
    nmap_scan(args.host, args.ports)
