Skip to content

Instantly share code, notes, and snippets.

@nirleka
Created February 22, 2012 08:20
Show Gist options
  • Save nirleka/1883388 to your computer and use it in GitHub Desktop.
Save nirleka/1883388 to your computer and use it in GitHub Desktop.
Parsing 4th level domain from file which contain domain
"""
host.txt generated from command: host -l domain (unix like)
"""
try:
f = open("host.txt", "r")
try:
lines = f.readlines()
before = ""
count = 0
for line in lines:
domain = line[0:line.find(' ')]
if (domain != before):
if (domain.count('.') == 3):
count += 1
print "{} : {}".format(domain, count)
before = domain
finally:
print count
f.close()
except IOError:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment