23
23
'name' : 'Reported abuse originating from this country' ,
24
24
'format' : '{0}' ,
25
25
'thousandSeparator' : '.' ,
26
- 'thresholdMax' : 2_000 ,
27
- 'thresholdMin' : 500
26
+ 'thresholdMax' : 2 ,
27
+ 'thresholdMin' : 1
28
28
},
29
29
'bot' : {
30
30
'name' : 'Reported bots' ,
46
46
'name' : 'Reported crawlers' ,
47
47
'format' : '{0}' ,
48
48
},
49
+ 'ip4' : {
50
+ 'name' : 'Reports from IPv4' ,
51
+ 'format' : '{0}' ,
52
+ },
53
+ 'ip6' : {
54
+ 'name' : 'Reports from IPv6' ,
55
+ 'format' : '{0}' ,
56
+ },
49
57
},
50
58
'values' : {},
51
59
}
54
62
55
63
# pylint: disable=E0606
56
64
def main ():
57
- with open (args .file , 'r' , encoding = 'utf-8' ) as f :
58
- raw = json_loads (f .read ())
65
+ with open (args .file_ip4 , 'r' , encoding = 'utf-8' ) as f :
66
+ raw4 = json_loads (f .read ())
67
+
68
+ with open (args .file_ip6 , 'r' , encoding = 'utf-8' ) as f :
69
+ raw6 = json_loads (f .read ())
59
70
60
71
with mmdb_database (args .country_db ) as m :
61
- for ips in raw .values ():
62
- for ip , reports in ips .items ():
63
- ip_md = m .get (ip )
64
- if ip_md ['country' ] not in DATA ['data' ]['values' ]:
65
- DATA ['data' ]['values' ][ip_md ['country' ]] = {c : 0 for c in CATEGORIES }
72
+ for ipv , ipv_db in {'ip4' : raw4 , 'ip6' : raw6 }.items ():
73
+ for ips in ipv_db .values ():
74
+ for ip , reports in ips .items ():
75
+ ip_md = m .get (ip )
76
+ if ip_md ['country' ] not in DATA ['data' ]['values' ]:
77
+ DATA ['data' ]['values' ][ip_md ['country' ]] = {c : 0 for c in CATEGORIES }
78
+ DATA ['data' ]['values' ][ip_md ['country' ]]['ip4' ] = 0
79
+ DATA ['data' ]['values' ][ip_md ['country' ]]['ip6' ] = 0
80
+
81
+ for c in CATEGORIES :
82
+ if c in reports :
83
+ DATA ['data' ]['values' ][ip_md ['country' ]][c ] += reports [c ]
66
84
67
- for c in CATEGORIES :
68
- if c in reports :
69
- DATA ['data' ]['values' ][ip_md ['country' ]][c ] += reports [c ]
85
+ DATA ['data' ]['values' ][ip_md ['country' ]][ipv ] += reports ['all' ]
70
86
71
87
DATA ['data' ]['values' ] = dict (sorted (DATA ['data' ]['values' ].items (), key = lambda item : item [1 ]['all' ], reverse = True ))
72
88
with open (SRC_PATH / 'world_map.json' , 'w' , encoding = 'utf-8' ) as f :
@@ -78,7 +94,8 @@ def main():
78
94
79
95
if __name__ == '__main__' :
80
96
parser = ArgumentParser ()
81
- parser .add_argument ('-f' , '--file' , help = 'JSON file to parse' , default = 'risk_ip4_med.json' )
97
+ parser .add_argument ('-4' , '--file-ip4' , help = 'IPv4 JSON file to parse' , default = 'risk_ip4_med.json' )
98
+ parser .add_argument ('-6' , '--file-ip6' , help = 'IPv6 JSON file to parse' , default = 'risk_ip6_med.json' )
82
99
parser .add_argument ('-c' , '--country-db' , help = 'MMDB country data to use (IPInfo)' , default = 'country_asn.mmdb' )
83
100
args = parser .parse_args ()
84
101
main ()
0 commit comments