1
0

added CPE449/geolocation

This commit is contained in:
Andrew Woodlee 2022-11-11 17:00:01 -06:00
parent bd4e2127fe
commit f242e70afa
3 changed files with 1115 additions and 0 deletions

Binary file not shown.

View File

@ -0,0 +1,41 @@
import pygeoip
import re as regex
ipAddrList = { }
ipAddrCountry = { }
geoip = pygeoip.GeoIP('GeoIP.dat')
loginFile = open("logins.txt")
loginList = loginFile.readlines()
ipAddrRegex = regex.compile(r'(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})')
uniqueIPs = 0
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
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:")
for ipCount in ipAddrList:
print(ipCount,":", ipAddrList.get(ipCount))
print("IP Addresses by country:")
for ipCountry in ipAddrCountry:
print(ipCountry, ":", ipAddrCountry.get(ipCountry))
print("\nNumber of unique IP addresses: ", uniqueIPs, "\n")
print("\nNumber of unique IP addresses by Country: ", uniqueIPsByCountry, "\n")

File diff suppressed because it is too large Load Diff