Advertisement
rfmonk

ipv4_convert.py

May 11th, 2014
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.39 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3.  
  4. import socket
  5. from binascii import hexlify
  6.  
  7. def convert_ipv4_addr():
  8.     for ip_addr in ['127.0.0.1', '192.168.0.1']:
  9.         packed_ip_addr = socket.inet_aton(ip_addr)
  10.         unpacked_ip_addr = socket.inet_ntoa(packed_ip_addr)
  11.         print "IP Address: %s => Packed: %s, Unpacked: %s"\
  12.         %(ip_addr, hexlify(packed_ip_addr), unpacked_ip_addr)
  13.  
  14. if __name__ == '__main__':
  15.     convert_ipv4_addr()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement