File tree 1 file changed +14
-16
lines changed
misp_modules/modules/expansion
1 file changed +14
-16
lines changed Original file line number Diff line number Diff line change 20
20
"gov" : "Government (USA)"
21
21
}
22
22
23
- codes = False
23
+
24
+ def parse_country_code (extension ):
25
+ # Retrieve a json full of country info
26
+ try :
27
+ codes = requests .get ("http://www.geognos.com/api/en/countries/info/all.json" ).json ()
28
+ except Exception :
29
+ return "http://www.geognos.com/api/en/countries/info/all.json not reachable"
30
+ if not codes .get ('StatusMsg' ) or not codes ["StatusMsg" ] == "OK" :
31
+ return 'Not able to get the countrycode references from http://www.geognos.com/api/en/countries/info/all.json'
32
+ for country in codes ['Results' ].values ():
33
+ if country ['CountryCodes' ]['tld' ] == extension :
34
+ return country ['Name' ]
35
+ return "Unknown"
24
36
25
37
26
38
def handler (q = False ):
27
- global codes
28
- if not codes :
29
- codes = requests .get ("http://www.geognos.com/api/en/countries/info/all.json" ).json ()
30
39
if q is False :
31
40
return False
32
41
request = json .loads (q )
@@ -36,18 +45,7 @@ def handler(q=False):
36
45
ext = domain .split ("." )[- 1 ]
37
46
38
47
# Check if it's a common, non country one
39
- if ext in common_tlds .keys ():
40
- val = common_tlds [ext ]
41
- else :
42
- # Retrieve a json full of country info
43
- if not codes ["StatusMsg" ] == "OK" :
44
- val = "Unknown"
45
- else :
46
- # Find our code based on TLD
47
- codes = codes ["Results" ]
48
- for code in codes .keys ():
49
- if codes [code ]["CountryCodes" ]["tld" ] == ext :
50
- val = codes [code ]["Name" ]
48
+ val = common_tlds [ext ] if ext in common_tlds .keys () else parse_country_code (ext )
51
49
r = {'results' : [{'types' : ['text' ], 'values' :[val ]}]}
52
50
return r
53
51
You can’t perform that action at this time.
0 commit comments