diff --git a/CPE449/geolocation/geoip.py b/CPE449/geolocation/geoip.py index 6942aa2..9e1d9a4 100644 --- a/CPE449/geolocation/geoip.py +++ b/CPE449/geolocation/geoip.py @@ -18,24 +18,22 @@ uniqueIPsByCountry = 0 for login in loginList: ipAddr = regex.split(ipAddrRegex, login) ip = ipAddr[1] - if ip in ipAddrList: - country = geoip.country_code_by_addr(ip) - if country not in ipAddrCountry.values(): - uniqueIPsByCountry += 1 + # use dictionary for number of IPs in a Country + country = geoip.country_code_by_addr(ip) + if country not in ipAddrCountry.values(): + uniqueIPsByCountry += 1 + ipAddrCountry[ip] = country + if ip in ipAddrList.keys(): ipAddrList[ip] += 1 else: - country = geoip.country_code_by_addr(ip) - if country not in ipAddrCountry.values(): - uniqueIPsByCountry += 1 - ipAddrCountry[ip] = country uniqueIPs+=1 ipAddrList[ip] = 1 -print("IP Addresses by count:") +print("\nIP Addresses by count:\n") for ipCount in ipAddrList: print(ipCount,":", ipAddrList.get(ipCount)) -print("IP Addresses by country:") +print("\nIP Addresses by country:\n") for ipCountry in ipAddrCountry: print(ipCountry, ":", ipAddrCountry.get(ipCountry)) -print("\nNumber of unique IP addresses: ", uniqueIPs, "\n") +print("\nNumber of unique IP addresses: ", uniqueIPs) print("\nNumber of unique IP addresses by Country: ", uniqueIPsByCountry, "\n") \ No newline at end of file