import socket
import struct


def ip2long(ip):
	"""
	Convert an IP string to long
	"""
	try:
		packedIP = socket.inet_aton(ip)
		res = struct.unpack("!L", packedIP)[0]
	except Exception:
		res = ''
	return res