parse.py 574 B

1234567891011121314151617181920212223242526272829303132
  1. #!/usr/local/bin/python
  2. import sys
  3. import re
  4. def parse_log(filename):
  5. hosts = []
  6. try:
  7. fh = open(filename, 'r')
  8. except:
  9. print "Unable to open logfile"
  10. sys.exit(1)
  11. for line in fh:
  12. matches = re.search('joins \((.+)\)', line)
  13. if matches:
  14. hostname = matches.group(1)
  15. if not hostname in hosts:
  16. hosts.append(hostname)
  17. fh.close()
  18. return hosts
  19. def main():
  20. hosts = parse_log(sys.argv[1])
  21. for host in hosts:
  22. print host
  23. if __name__ == "__main__":
  24. main()