Initial commit
This commit is contained in:
39
geo-firewall.py
Executable file
39
geo-firewall.py
Executable file
@@ -0,0 +1,39 @@
|
||||
#!/usr/bin/python3
|
||||
import netaddr
|
||||
import csv
|
||||
import sys
|
||||
import os
|
||||
|
||||
# inFilePath = 'GeoIPCountryWhois.csv'
|
||||
# inFilePath = 'au.csv'
|
||||
inFilePath = 'firewall.txt'
|
||||
|
||||
os.system('sudo ipset create TEST2 hash:net -exist')
|
||||
os.system('sudo ipset flush TEST2')
|
||||
|
||||
iplist = []
|
||||
|
||||
with open(inFilePath, 'r') as inFile:
|
||||
# fieldnames = ['StartIP', 'EndIP', 'DecIPStart', 'DecIPEnd', 'CountryCode', "Country"]
|
||||
# fieldnames = 'StartIP', 'EndIP','Number','Date']
|
||||
# csvReader = csv.DictReader(inFile, fieldnames=fieldnames)
|
||||
|
||||
# for row in csvReader:
|
||||
# if row['CountryCode'] == 'AU':
|
||||
# iplist.extend(netaddr.iprange_to_cidrs(row['StartIP'], row['EndIP']))
|
||||
|
||||
for row in inFile:
|
||||
print(row)
|
||||
if not row.startswith("#"):
|
||||
iplist.extend(netaddr.IPNetwork(row))
|
||||
|
||||
print("########################################")
|
||||
|
||||
|
||||
summary_subnets = netaddr.cidr_merge(iplist)
|
||||
for subnet in summary_subnets:
|
||||
print(subnet)
|
||||
os.system('sudo ipset add TEST2 ' + str(subnet))
|
||||
|
||||
os.system('sudo ipset swap TEST TEST2')
|
||||
os.system('sudo ipset destroy TEST2')
|
||||
Reference in New Issue
Block a user