Skip to content

Instantly share code, notes, and snippets.

@v2e4lisp
Last active December 11, 2015 10:29
Show Gist options
  • Save v2e4lisp/4587571 to your computer and use it in GitHub Desktop.
Save v2e4lisp/4587571 to your computer and use it in GitHub Desktop.
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