Skip to content

Instantly share code, notes, and snippets.

@b4tman
Created September 27, 2024 10:29
Show Gist options
  • Save b4tman/41c71dfc30cf9388ae73425f6d7d52c2 to your computer and use it in GitHub Desktop.
Save b4tman/41c71dfc30cf9388ae73425f6d7d52c2 to your computer and use it in GitHub Desktop.
int to IPv4 and IPv4 to int
ip2int = lambda ip: int("".join(map(lambda x: f"{int(x):08b}", ip.split("."))), 2)
int2ip = lambda x: ".".join(str(int(f"{x:032b}"[i:i+8], 2)) for i in range(0,25,8))
print(x := ip2int("127.0.0.1"), int2ip(x))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment