Search code examples
pythonsecuritynmapport-scanning

Passing a List of IP address to get port scanned in python (libnmap)


I am working on a python script which basically scans port on a IP address ,& I am using the libnmap library to do so , referring the docs at : https://libnmap.readthedocs.org/en/latest/process.html#purpose-of-libnmap-process

what i am hoping to do is read a external file which contains list of IP address to be scanned and pass each of the IP address as :

file_object = open(file_containg_ip_to_be_port_scanned, r)

    if __name__ == "__main__":
        report = do_scan("pass_ip_here", "-sV")
        if report:
            print_scan(report)

how can I achieve this ?


Solution

  • Looks like you want something like this:

    with open('ip_list.txt') as f:
        for ip in f.read().splitlines():
            report = do_scan(ip, "-sV")
            if report:
                print_scan(report)