传递 IP 地址列表以在 python (libnmap) 中扫描端口

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

我正在开发一个 python 脚本,它基本上扫描 IP 地址上的端口,并且我正在使用 libnmap 库来执行此操作,参考文档位于:https://libnmap.readthedocs.org/en/latest/process.html#purpose-of-libnmap-process

我希望做的是读取一个包含要扫描的 IP 地址列表的外部文件,并将每个 IP 地址传递为:

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)

我怎样才能做到这一点?

看起来你想要这样的东西:

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