Skip to content

Instantly share code, notes, and snippets.

@rains31
Created August 25, 2014 06:50
Show Gist options
  • Select an option

  • Save rains31/686c6f195985f08e4809 to your computer and use it in GitHub Desktop.

Select an option

Save rains31/686c6f195985f08e4809 to your computer and use it in GitHub Desktop.
ip地址和数字形式互转
#IP地址之间的转换
import socket
import struct
def ip2long (ip):
return struct.unpack("!I", socket.inet_aton(ip))[0]
def long2ip (lint):
return socket.inet_ntoa(struct.pack("!I", lint))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment