
def network():
    '''
    @description: collects network information such as listening ports, DNS info, active connections, firewall rules, etc
    @author: ohdae [bindshell@live.com]
    @short: enumerate network info
    '''
    log_msg("\n\n [ Network Module ]")
    log_msg("\n Start Time: %s" % logtime)


    print("[+] Collecting network info: services, ports, active connections, dns, gateways, etc...")
    maketemp("network")
    networkdir = Temp_Dir+"/network"
    os.chdir(networkdir) 

    proc = Popen('netstat --tcp --listening',
         shell=True,
         stdout=PIPE,
         )
    output = proc.communicate()[0]

    file = open("nstat.txt","a")
    for items in output:
        file.write(items),
    file.close() 

    os.system("lsof -nPi > lsof.txt")
    ports = ["nstat.txt","lsof.txt"]
    combinefiles("Connections.txt", ports)
    os.system("rm nstat.txt lsof.txt")

    if currentuser == "root" and whereis('iptables') is not None:
        os.system("iptables -L -n > iptablesLN.txt") 
        os.system("iptables-save > iptables_save.txt")
        log_msg("\n IPTables information saved.")
    else:
        pass

    os.system("ifconfig -a > ifconfig.txt")


    if distro == "ubuntu" or distro2 == "Ubuntu" is True:
        os.system("hostname -I > IPAddresses.txt")
    else:
        s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        s.connect(("google.com",80))
        localIP = (s.getsockname()[0])
        s.close()
        splitIP = localIP.split('.')
        splitIP[3:] = (['0/24'])
        IPRange = ".".join(splitIP)
        externalIP = urllib2.urlopen("http://myip.ozymo.com/").read()
        text = ("External IP Address: " + externalIP + "\nInternal IP Address: " + localIP + "\nInternal IP Range: " + IPRange)
        writenew("IPAddresses.txt", text)
   
    os.system("hostname -f > hostname.txt")
   
    netfiles = ["IPAddresses.txt","hostname.txt","ifconfig.txt"]
    combinefiles("NetworkInfo.txt", netfiles)
    os.system("rm IPAddresses.txt hostname.txt ifconfig.txt")

    network = [ "/etc/hosts.deny", "/etc/hosts.allow", "/etc/inetd.conf", "/etc/host.conf", "/etc/resolv.conf" ]
    for x in network:
        copy2temp(x, networkdir)
   

