text
stringlengths
1
93.6k
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#----------------------------------------------------------------------------------
# Wrote this in a DC when i had to test > 10 VLANS from a trunk port cos im lazy.
# Fairly simple to use and really helpful. All that is required is 8021q kernel
# module to be installed.
#
# The CSV file should be in the order:
#
# IP,Netmask,Gateway,VlanID,Comment
#
# ~ \x90
#
import os
import sys
import commands
import time
VERSION = "1.1"
m = False
arp = False
def pc(c, str):
if c == 1:
print "\033[1;32m[+]\033[0m %s" % str # Green
elif c == 2:
print "\033[1;31m[!]\033[0m %s" % str # Red
elif c == 3:
print "\033[1;33m[?]\033[0m %s" % str # Info
else:
print "wu w0t m8?!"
def init(iface, c):
x = commands.getstatusoutput("ifconfig %s" % iface)[1]
if "Device not found" in x:
pc(2, x)
exit(1)
pc(3, "Interface: '%s'" % iface)
pc(3,"Loading kernel module 8021q...")
x = commands.getstatusoutput("modprobe 8021q")[1]
if x:
pc(2, "Failed to load kernel module 8021q. Install with local package manager.")
exit(1)
try:
f = open(c, "r").close()
except:
pc(2, "Error opening file '%s'" % c)
exit(1)
def c_vlans(c,all, make_flag):
configs = []
f = open(c, "r")
for line in f.readlines():
if len(line) > 1:
if not '#' in line[0]:
configs.append(line.split(","))
num_all_configs = len(configs)
num_exit = len(configs)+1
rng = range( 0, num_all_configs )
rng.append(num_all_configs)
rng.append(num_exit)
ch = -1
if all == 0:
while (ch not in rng):
pc(1, "-- Choose VLAN to apply --")
for cnf in configs:
print "\033[1;32m[%d]\033[0m\tVID: \033[1;32m'%s'\033[0m\tIP: '%s'\tNetmask: '%s'\tGateway: '%s'\tComment: '%s'" % (configs.index(cnf), cnf[3], cnf[0], cnf[1], cnf[2], cnf[4].strip())
print "\033[1;32m[%d]\033[0m\tEnable all vlans" % num_all_configs
print "\033[1;32m[%d]\033[0m\tExit" % num_exit
try:
ch = int(raw_input("\033[1;31m > \033[0m"))
except:
continue
if ch == num_exit:
exit(0)
elif ch != num_all_configs: