I would like to output to tabular CSV format for the code below?

February 12, 2018 691 views
Ansible Applications

I would like to output to tabular CSV format for the code below?

1 comment
  • import socket,datetime
    ip_list = open("c:\script_run\ips.txt").readlines()
    port_list = open("c:\script_run\ports.txt").readlines()
    open_ports = []
    failed_ports = []
    def pscan(ips,ports):
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        s.settimeout(2)
        try:
            con = s.connect((ips,ports))
            return True
        except:
            return False
    print ('This Scan started on' , (datetime.datetime.utcnow() - datetime.timedelta(hours=5)))
    for ips in ip_list:
        for ports in port_list:
            con = pscan((ips.strip()),(ports.strip()))
            if con == True:
                open_ports.append(ports.strip())
            else:
                failed_ports.append(ports.strip())
        print ()
        print ( "Device IP - " + ips.strip(),":Yes :".join(map(str, enumerate(open_ports))), \
         ":Nope :".join(map(str,enumerate(failed_ports))))
        open_ports = []
        failed_ports = []
    print ('This Scan Ended on' ,(datetime.datetime.utcnow() - datetime.timedelta(hours=5)))
    
    input ("Execution Complete-Press Enter to exist")
    
    edited by kamaln7
Be the first one to answer this question.