Created
September 27, 2024 10:29
-
-
Save b4tman/41c71dfc30cf9388ae73425f6d7d52c2 to your computer and use it in GitHub Desktop.
int to IPv4 and IPv4 to int
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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