Advertisement
cmiN

addr2name

May 2nd, 2012
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.52 KB | None | 0 0
  1. #! /usr/bin/env python
  2.  
  3.  
  4. from socket import gethostbyaddr
  5. from sys import argv
  6.  
  7.  
  8. DELIM = ","
  9.  
  10.  
  11. def main():
  12.     if len(argv) != 3:
  13.         print "Usage: %s infile outfile" % argv[0]
  14.         return
  15.     with open(argv[1], "r") as fin, open(argv[2], "w") as fout:
  16.         for line in fin:
  17.             chunk = line.strip().split(DELIM)
  18.             string = "{user}@{host},{pwd}\n".format(user=chunk[1], pwd=chunk[2], host=gethostbyaddr(chunk[0])[0])
  19.             fout.write(string)
  20.  
  21.  
  22. if __name__ == "__main__":
  23.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement