Last active
December 11, 2015 10:29
-
-
Save v2e4lisp/4587571 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def getIP (record): | |
return record[:record.index(" ")] | |
def go (): | |
ips = dict() | |
for line in open("access.log", "r"): | |
ip = getIP(line) | |
ips[ip] = ips.get(ip, 0) + 1 | |
ips = sorted(ips.items(), key=lambda x: -x[1]) | |
prettify(ips) | |
def prettify (records): | |
for i in records: | |
print "%15s %10d" % i | |
go() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment