usr bin python def bin2ip bin octs bin long bin last long mask 24 16 f

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
#!/usr/bin/python
def bin2ip(bin):
octs = []
bin = long(bin)
last = long(0)
mask = [24, 16, 8, 0]
for i in range(4):
oct = (bin - last) >> mask[i]
last += (oct << mask[i])
octs.append(str(oct))
print ".".join(octs)
bin2ip('3232236805')
penpen@handy:~$ python lol.py
192.168.5.5