Skip to content

Instantly share code, notes, and snippets.

@nikitalarionov
Created May 5, 2021 00:03
Show Gist options
  • Save nikitalarionov/3b752eb108376c28ad54b332a805e3bd to your computer and use it in GitHub Desktop.
Save nikitalarionov/3b752eb108376c28ad54b332a805e3bd to your computer and use it in GitHub Desktop.
convert ip to num
def iptoint(ip):
h=list(map(int,ip.split(".")))
return (h[0]<<24)+(h[1]<<16)+(h[2]<<8)+(h[3]<<0)
def inttoip(ip):
return ".".join(map(str,[((ip>>24)&0xff),((ip>>16)&0xff),((ip>>8)&0xff),((ip>>0)&0xff)]))
iptoint("8.8.8.8") # 134744072
inttoip(134744072) # 8.8.8.8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment