added CPE449/geolocation
This commit is contained in:
		
							
								
								
									
										
											BIN
										
									
								
								CPE449/geolocation/GeoIP.dat
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								CPE449/geolocation/GeoIP.dat
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										41
									
								
								CPE449/geolocation/geoip.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								CPE449/geolocation/geoip.py
									
									
									
									
									
										Normal 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") | ||||||
							
								
								
									
										1074
									
								
								CPE449/geolocation/logins.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1074
									
								
								CPE449/geolocation/logins.txt
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
		Reference in New Issue
	
	Block a user