示例#1
0
def main():
    global debug_script
    global send_email
    global email_from
    global email_pass
    global imap_username
    global nmap_location

    global script_directory
    global scan_directory
    global scan_history_file
    global hosts_directory
    global instance_number

    instance_number = randint(1000, 99999)
    file_managment.logger("Script started, instance number: " + str(instance_number))

    # Script start
    script_directory = "/root/port-watcher/"
    # script_directory = "/home/azureuser/port-watcher/"
    config_options = file_managment.load_config_file(script_directory + "config.json")

    debug_script = config_options["debug_script"]
    send_email = config_options["send_email"]
    email_from = config_options["email_from"]
    email_pass = config_options["email_pass"]
    imap_username = config_options["imap_username"]
    nmap_location = config_options["nmap_location"]

    scan_directory = script_directory + "scans/"
    scan_history_file = script_directory + "scans/scan_history.txt"
    hosts_directory = script_directory + "hosts/"
    schedule_file = script_directory + "schedule.csv"

    try:
        # Load config and data files
        schedule_obj = file_managment.schedule(schedule_file)
        subnets_info = file_managment.load_subnets_file()
        all_hosts = file_managment.host_list()
        scan_history = file_managment.scan_history(scan_history_file)

        run_next_scan(subnets_info, schedule_obj, send_email, debug_script)
        if debug_script == True:
            print "Scans Completed"
        file_managment.logger("Pending scans completed.")
        file_managment.logger("Script complete.")
    except Exception, e:
        file_managment.logger("Error running script: " + str(e))
        file_managment.logger("Traceback " + str(instance_number) + ": " + str(traceback.format_exc()))
示例#2
0
#!/usr/bin/python

import datetime
import file_managment

# Print report header
print "Open Ports Report"
print "Report date: " + str(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
print "--------------------------------"
print ""
print ""

# Load all hosts
hosts_obj = file_managment.host_list()
all_hosts = hosts_obj.hosts_list

#Get all ports open on last scan
for host_ip in all_hosts:
    print host_ip
    host_obj = file_managment.get_host(host_ip, "ipv4")
    scan_timestamp = datetime.datetime.fromtimestamp(host_obj.get_latest_scans()[0].unix_time).strftime('%Y-%m-%d %H:%M:%S')
    print "Last Scan at " + str(scan_timestamp)
    print "Open Ports:"
    print host_obj.get_latest_scans()[0].open_ports
    print "--------------------------------"
    print ""