-
Notifications
You must be signed in to change notification settings - Fork 0
/
modify_rules.py
47 lines (37 loc) · 1.12 KB
/
modify_rules.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import json
rules_dict = None
def check_rules():
with open("rules.json", "r") as fid:
rules_dict = json.load(fid)
print(rules_dict)
return rules_dict
def add_rule(name, source_ip, depth,action):
with open("rules.json", "r") as fid:
rules_dict = json.load(fid)
rules_dict[name]['ip'] = source_ip
rules_dict[name]['depth'] = depth
rules_dict[name]['action']= action
with open("rules.json", "w") as fid:
json.dump(rules_dict, fid)
print(rules_dict)
return 0
def del_rule(name):
with open("rules.json", "r") as fid:
rules_dict = json.load(fid)
del rules_dict[name]
with open("rules.json", "w") as fid:
json.dump(rules_dict, fid)
print(rules_dict)
return 0
if __name__ == '__main__':
rules_dict = None
with open("rules.json","r") as fid:
rules_dict = json.load(fid)
print(rules_dict['rule3']['action'])
rules_dict['rule3']['action']=1-rules_dict['rule3']['action']
with open("rules.json","w") as fid:
json.dump(rules_dict,fid)
del rules_dict['rule3']
print(rules_dict)
rules_dict['rule3']=1
print(rules_dict)