text
stringlengths
1
93.6k
configs = [configs[ch]]
for cnf in configs:
e = commands.getstatusoutput("vconfig add %s %s" % (iface, cnf[3]))[1]
if "exists" in e:
pc(3, e)
elif not "Added VLAN with VID ==" in e:
pc(2, e)
continue
time.sleep(0.5)
if not (cnf[0].lower() == "dhcp"):
e = commands.getstatusoutput("ifconfig %s.%s %s netmask %s" % (iface, cnf[3], cnf[0], cnf[1]) )[1]
else:
os.system("dhclient %s.%s" % (iface, cnf[3]) )
if e:
pc(2, e)
exit(1)
time.sleep(0.5)
if " " in cnf[4]:
cnf[4] = cnf[4].strip().replace(" ", "_")
else:
cnf[4] = cnf[4].strip()
# CHECK IF WE HAVE SET A GATEWAY
if (len(cnf[2]) > 0):
commands.getstatusoutput("route add default gw %s %s.%s" % (cnf[2], iface, cnf[3]))[1]
if "File exists" in e:
pc(3, e)
elif e:
pc(2, e + " - Skipping but will still configure IP...")
continue
pc(1, "VID '%s' : '%s.%s ip:'%s' netmask:'%s' gateway:'%s' (Comment: '%s')" % (cnf[3], iface, cnf[3], cnf[0], cnf[1], cnf[2], cnf[4]))
else:
pc(1, "VID '%s' : '%s.%s ip:'%s' netmask:'%s' gateway:'N/A' (Comment: '%s')" % (cnf[3], iface, cnf[3], cnf[0], cnf[1], cnf[4]))
if ch != num_all_configs and ch != -1:
pc(3, "ifconfig %s.%s\n" % (iface, configs[0][3]) )
os.system("ifconfig %s.%s" % (iface, configs[0][3]) )
else:
os.system("ifconfig")
pc(3, "Routing table\n")
os.system("route -n")
if (m):
for cnf in configs:
try:
os.mkdir(cnf[4]) # create the VLAN directory for testing purposes.
except OSError:
pc(3, "Directory '%s' already exists. Skipping ARP scan. (Remove all VLAN folders to ARP scan, this is more of a safety feature to avoid losing any test data)" % cnf[4])
if (arp):
if ( len(commands.getstatusoutput("which arp-scan")[1]) > 1):
pc(1, "ARP Scanning VLAN '%s' using 'arp-scan'" % cnf[3])
os.system("arp-scan -l -I %s.%s > %s/arp-scan_live_hosts.txt" % ( iface, cnf[3], cnf[4] ))
os.system("cat %s/arp-scan_live_hosts.txt | grep -E '([0-9|a-f]{2}:){5}' | awk '{print $1}' > %s/live_ips.txt" % ( cnf[4], cnf[4]))
if ( os.path.getsize("%s/live_ips.txt" % cnf[4] ) == 0 ):
pc(3, "VLAN '%s' appears to be empty, no hosts returned from ARP scan." % cnf[3] )
os.system("touch %s/EMPTY_VLAN" % cnf[4] )
elif ( len(commands.getstatusoutput("which nmap")[1]) > 1):
pc(1, "ARP Scanning VLAN '%s' using 'nmap '" % cnf[3])
os.system("nmap -sP -n %s -oN > %s/nmap-ARP-sP-n_live_hosts.txt" % (cnf[3], cnf[4] ))
os.system("cat %s/nmap-ARP-sP-n_live_hosts.txt | grep 'scan report for' | cut -d ' ' -f 5 > %s/live_ips.txt" % ( cnf[4], cnf[4] ))
else:
pc(2, "Could not find 'nmap' or 'arp-scan' binary in $PATH. Could not perform ARP scan.")
def rem_vlans(iface, all, id):
if all:
print commands.getstatusoutput("for i in $(ifconfig | grep \"eth0\.\" | awk '{print $1}'); do vconfig rem $i; done")[1]
else:
print commands.getstatusoutput("vconfig rem %s.%s" % (iface,id) )[1]
pc(1, "Done")
def usage():
pc(2, "Usage: %s -i [interface] -c [network_config_file.csv] [options]" % sys.argv[0])
print "\nOptions:"
print "\tBy default, this tool will offer an interactive menu, to enable all VLANS use -a"
print ""
print "\t-i [interface]\tInterface to configure VLAN ID."