Skip to content

Instantly share code, notes, and snippets.

@Blizzardo1
Created February 13, 2021 22:18
Show Gist options
  • Save Blizzardo1/3e43f3959f477461e576fae1d557611a to your computer and use it in GitHub Desktop.
Save Blizzardo1/3e43f3959f477461e576fae1d557611a to your computer and use it in GitHub Desktop.
Python script for Vyatta flavored configurations. Adds an IP to a block list.
#!/usr/bin/env python
import os
import sys
import vyatta
run = '/opt/vyatta/sbin/vyatta-cfg-cmd-wrapper'
runusr = '/opt/vyatta/bin/vyatta-op-cmd-wrapper'
red=31
green=32
reset=37
def make_color(color):
return '\033[1;%d;40m'%color
def call(command):
return os.popen(command).read()
def callusr(command):
cmd = '%s %s'%(runusr, command)
return call(cmd)
def callcfg(command):
cmd = '%s %s'%(run, command)
return call(cmd)
def commit():
vyatta.call('commit')
def save():
vyatta.call('save')
def main(args):
if len(args) < 2:
print ("%s <ip>" % args[0])
return
callcfg('begin')
callcfg("set firewall group address-group BlockedIPs address %s" % args[1])
commit()
callcfg('end')
save()
main(sys.argv)
# This is not a runnable script, rather instructions to use the script above effectively.
# I use rule 666 in my WAN_IN firewall because any IP I block deserves a special spot in Hell. sosumi
configure
edit firewall name WAN_IN rule 666
set action drop
set source group address-group BlockedIPs
exit
set firewall group address-group BlockedIPs
commit;save
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment