58 lines
1.4 KiB
Python
58 lines
1.4 KiB
Python
|
#! /usr/bin/python3
|
||
|
import json
|
||
|
|
||
|
RULES = {
|
||
|
"template":{"URL": "http://{0}/api/v1/firewall/rule",
|
||
|
"TAG":1,
|
||
|
"DATA":{"type":"block",
|
||
|
"interface":"wan",
|
||
|
"ipprotocol":"inet",
|
||
|
"protocol":"tcp",
|
||
|
"src":"",
|
||
|
"srcport":"any",
|
||
|
"dst":"any",
|
||
|
"dstport":"any",
|
||
|
"apply":False
|
||
|
}
|
||
|
},
|
||
|
"ip_ranges": [{
|
||
|
"template": "172.16.{0}.0/24",
|
||
|
"low": 1,
|
||
|
"high": 15
|
||
|
}, {
|
||
|
"template": "10.{0}.1.0/24",
|
||
|
"low": 1,
|
||
|
"high": 254
|
||
|
},{
|
||
|
"template": "192.168.{0}.0/16",
|
||
|
"low": 16,
|
||
|
"high": 254
|
||
|
}
|
||
|
]
|
||
|
}
|
||
|
|
||
|
|
||
|
def main():
|
||
|
rules = []
|
||
|
for ip_range in RULES["ip_ranges"]:
|
||
|
for x in range(ip_range["low"], ip_range["high"]+1):
|
||
|
ip = ip_range["template"].format(x)
|
||
|
|
||
|
rule = RULES["template"]
|
||
|
rule["DATA"]["src"] = ip
|
||
|
|
||
|
rules.append(json.dumps(rule))
|
||
|
|
||
|
|
||
|
with open("rules.json","w") as file:
|
||
|
file.write("[")
|
||
|
for i in range(len(rules)):
|
||
|
file.write(str(rules[i]))
|
||
|
if i +1 != len(rules):
|
||
|
file.write(",\n")
|
||
|
file.write("]")
|
||
|
|
||
|
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
main()
|