Question

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

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

Subscribe
Share
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")

Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!