added portScanDetection
This commit is contained in:
@ -1,39 +0,0 @@
|
||||
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]
|
||||
# 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:
|
||||
uniqueIPs+=1
|
||||
ipAddrList[ip] = 1
|
||||
|
||||
print("\nIP Addresses by count:\n")
|
||||
for ipCount in ipAddrList:
|
||||
print(ipCount,":", ipAddrList.get(ipCount))
|
||||
print("\nIP Addresses by country:\n")
|
||||
for ipCountry in ipAddrCountry:
|
||||
print(ipCountry, ":", ipAddrCountry.get(ipCountry))
|
||||
print("\nNumber of unique IP addresses: ", uniqueIPs)
|
||||
print("\nNumber of unique IP addresses by Country: ", uniqueIPsByCountry, "\n")
|
55
CPE449/geolocation/geolocate.py
Normal file
55
CPE449/geolocation/geolocate.py
Normal file
@ -0,0 +1,55 @@
|
||||
import pygeoip
|
||||
import re as regex
|
||||
|
||||
ipAddrList = { }
|
||||
|
||||
ipAddrCountryCount = { }
|
||||
ipAddrCountries = { }
|
||||
|
||||
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 ipAddrCountryCount.values():
|
||||
uniqueIPsByCountry += 1
|
||||
ipAddrList[ip] += 1
|
||||
else:
|
||||
country = geoip.country_code_by_addr(ip)
|
||||
if country not in ipAddrCountryCount.values():
|
||||
uniqueIPsByCountry += 1
|
||||
ipAddrCountries[ip] = country
|
||||
uniqueIPs+=1
|
||||
ipAddrList[ip] = 1
|
||||
|
||||
for ip in ipAddrList.keys():
|
||||
# use dictionary for number of IPs in a Country
|
||||
country = geoip.country_code_by_addr(ip)
|
||||
if country in ipAddrCountryCount:
|
||||
ipAddrCountryCount[country] += 1
|
||||
else:
|
||||
ipAddrCountryCount[country] = 1
|
||||
|
||||
print("\nIP Addresses by occurrence:\n")
|
||||
for ipCount in ipAddrList:
|
||||
print(ipCount,":", ipAddrList.get(ipCount))
|
||||
|
||||
print("\nIP Addresses by country:\n")
|
||||
for ipCountry in ipAddrCountries:
|
||||
print(ipCountry, ":", ipAddrCountries.get(ipCountry))
|
||||
|
||||
print("\nIP Address count from countries:\n")
|
||||
for ipCountry in ipAddrCountryCount:
|
||||
print(ipCountry, ":", ipAddrCountryCount.get(ipCountry))
|
||||
|
||||
print("\nNumber of unique IP addresses: ", uniqueIPs)
|
Reference in New Issue
Block a user