Skip to content

Instantly share code, notes, and snippets.

@jinie
Created July 17, 2015 12:12
Show Gist options
  • Save jinie/712d397cfa37bcb836b5 to your computer and use it in GitHub Desktop.
Save jinie/712d397cfa37bcb836b5 to your computer and use it in GitHub Desktop.
EdgeOS GeoIP blocking
#!/usr/bin/env python
import os
import urllib2
countries={'DK':'denmark'}
os.system("/opt/vyatta/sbin/vyatta-cfg-cmd-wrapper begin")
for country in countries.keys():
url = "http://www.ipdeny.com/ipblocks/data/aggregated/%s-aggregated.zone" % country.lower()
os.system("/opt/vyatta/sbin/vyatta-cfg-cmd-wrapper delete firewall group network-group %s" % countries[country])
os.system("/opt/vyatta/sbin/vyatta-cfg-cmd-wrapper set firewall group network-group %s" % countries[country])
for ip in urllib2.urlopen(url).readlines():
os.system("/opt/vyatta/sbin/vyatta-cfg-cmd-wrapper set firewall group network-group %s network %s" % (countries[country],ip))
os.system("/opt/vyatta/sbin/vyatta-cfg-cmd-wrapper commit")
os.system("/opt/vyatta/sbin/vyatta-cfg-cmd-wrapper end")
@uhue
Copy link

uhue commented Jul 27, 2020

Hey just wanted to let you know that its working. Also I assume this script wont work with IPv6?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment