diff --git a/asn-block-generator.py b/asn-block-generator.py index d3a0c9f..0cfe5d9 100644 --- a/asn-block-generator.py +++ b/asn-block-generator.py @@ -37,6 +37,14 @@ class IPParser: print("Using NGINX format") self.writeNginx() return + case "nginxGeo": + print("Using NGINX Geo format") + self.writeNginxGeo() + return + case "nginxMap": + print("Using NGINX Map format") + self.writeNginxMap() + return case "iptables": print("Using IPTables format") self.writeIptables() @@ -62,6 +70,36 @@ class IPParser: for ip in self.ip_v6: f.write('deny %s;\n' % ip) + def writeNginxGeo(self): + with open(f'{args.asn}-nginx-geo-ipv4.conf', 'w') as f: + f.write('geo $asn-%s {\n' % args.asn) + f.write('\tdefault 0;\n') + for ip in self.ip_v4: + f.write('\t%s 1;\n' % ip) + f.write('}') + + with open(f'{args.asn}-nginx-geo-ipv6.conf', 'w') as f: + f.write('geo $asn-%s {\n' % args.asn) + f.write('\tdefault 0;\n') + for ip in self.ip_v6: + f.write('\t%s 1;\n' % ip) + f.write('}') + + def writeNginxMap(self): + with open(f'{args.asn}-nginx-map-ipv4.conf', 'w') as f: + f.write('map $remote_addr $asn {\n') + f.write('\tdefault 0;\n') + for ip in self.ip_v4: + f.write('\t%s %s;\n' % (ip, args.asn)) + f.write('}') + + with open(f'{args.asn}-nginx-map-ipv6.conf', 'w') as f: + f.write('map $remote_addr $asn {\n') + f.write('\tdefault 0;\n') + for ip in self.ip_v6: + f.write('\t%s %s;\n' % (ip, args.asn)) + f.write('}') + def writeIptables(self): with open(f'{args.asn}-iptables-ipv4.txt', 'w') as f: for ip in self.ip_v4: