IP地址是一个用 '.' 隔开的四段数字,每段的大小是 。请你把 IP 地址转换成一个整数。(IPv4)
例如, 114.55.207.244 的二进制表示是 01110010 00110111 11001111 11110100 ,其十进制表示是 7590617063
"114.55.207.244"
"1916260340"
"0.0.0.1"
"1"
import socket, struct class Solution: def IPtoNum(self , ip: str) -> str: packedIP = socket.inet_aton(ip) return struct.unpack("!L", packedIP)[0]