Created
November 14, 2014 02:20
-
-
Save andfoy/673dd0d4806ad6c998b5 to your computer and use it in GitHub Desktop.
This file contains 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
def ip2bin(ip): | |
num = [int(n) for n in ip.split('.')] | |
bits = ['0'*(8-len(bin(n)[2:]))+bin(n)[2:] for n in num] | |
return ''.join(bits) | |
def bin2ip(bin): | |
ip = [str(int(bin[i:i+8], 2))+'.' for i in range(0, 32, 8)] | |
return ''.join(ip)[0:-1] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment