*More fully fledged applications can be found on the Products page. The Bash page is dedicated to fully commented oneliners, and a MySQL quick reference is available here.
# Open and Read:
fname = "geo_ips.txt"
with open(fname) as f:
data = [line.strip('\n') for line in f.readlines()]
# Calculate Freq:
countries = []
freqs = []
for country in data:
if country != "ddress not found": #remove the lookup failures
if not country in countries:
countries.append(country)
freqs.append(1)
else:
freqs[countries.index(country)] = freqs[countries.index(country)] + 1
# Tuple it for sorting:
cf = []
for i in range(0, len(countries)):
t = (countries[i], freqs[i])
cf.append(t)
# Sort, Highest to Lowest:
cf_sorted = sorted(cf, key=lambda val: val[1], reverse=True)
# Generate Output:
fout = open("auth_attempts.txt", 'w')
fout.write("<p><b>Origin --> # Attempts</b></p>\n")
for i in range(0, len(countries)):
line = str(cf_sorted[i][0]) + " --> " + str(cf_sorted[i][1])
# print line
fout.write(line)
fout.write('\n')
fout.close()