import socket
def valid_ip(str):
try:
socket.inet_aton(str)
return True
except:
return False
def ip2long(str):
if str == 0:
return 0
check = valid_ip(str)
if check is False:
return 0
tmp = str.split(".")
return (int(tmp[0]) << 24) + (int(tmp[1]) << 16) + (int(tmp[2]) << 8) + int(tmp[3]);
【python实现】ip转换为Long类型
最新推荐文章于 2023-05-29 05:46:33 发布