#ip_convert.py #to and from 32-bits to dotted quad decimal #convert 32-bit string to dotted quad ip_addr = '01010111000101001010001010111110' for d in range(4): print(int(ip_addr[d*8:(d+1)*8],base=2), end="") if d < 3: print(".", end="") print() # OR: for i in range(0,32,8): print(int(ip_addr[i:i+8],base=2), end=".") print() #convert dotted quad to 32 bits string quad = '123.94.210.9' ip_addr = "" for d in quad.split("."): ip_addr += format(int(d),'08b') print(ip_addr)