js code
var ip2long = function(ip){ip = ip.split(".");return (((ip[0] << 24) | (ip[1] << 16) | (ip[2] << 8) | ip[3]) >>> 0)}
var long2ip = function(ip){return [(ip >> 24) & 0xff,(ip >> 16) & 0xff,(ip >> 8) & 0xff,ip & 0xff].join(".")}
/*用于防止运营商修改地址*/
Python socket module
# 导入相关模块包
import socket
import struct
# 将IP从字符串转为整型
>>> int(socket.inet_aton('127.0.0.1').encode('hex'),16)
2130706433
# 将IP从整型转为字符串
>>> socket.inet_ntoa(struct.pack("!I",2130706433))
'127.0.0.1'
python lambda 形式
long2ip = lambda x: '.'.join([str(x/(256**i)%256) for i in range(3,-1,-1)])
ip2long = lambda x:sum([256**j*int(i) for j,i in enumerate(x.split('.')[::-1])])
MySql 函数
MySQL中存在INET_ATON() 、INET_NTOA()函数进行IP整型和字符串之间的转换