Skip to content

Instantly share code, notes, and snippets.

Created June 9, 2015 10:50
Show Gist options
  • Save anonymous/cd4c4227133ad4166edd to your computer and use it in GitHub Desktop.
Save anonymous/cd4c4227133ad4166edd to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
########################################################################
#
# Copyright (c) 2015 Baidu.com, Inc. All Rights Reserved
#
########################################################################
'''
File: int2ip.py
Author: zhanglistar(zhanglistar@baidu.com)
Date: 2015/06/09 18:48:48
'''
import sys
import socket
import struct
def ip2int(addr):
return struct.unpack("!I", socket.inet_aton(addr))[0]
def int2ip(addr):
return socket.inet_ntoa(struct.pack("!I", addr))
if __name__ == '__main__':
print int2ip(int(sys.argv[1]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment