First attempt to organise the code
[re6stnet.git] / utils.py
1 import time
2
3 def log(message, verbose_level):
4 if verbose >= verbose_level:
5 print time.strftime("%d-%m-%Y %H:%M:%S : " + message)
6
7 def ipFromBin(prefix):
8 prefix = hex(int(prefix, 2))[2:]
9 ip = ''
10 for i in xrange(0, len(prefix) - 1, 4):
11 ip += prefix[i:i+4] + ':'
12 return ip.rstrip(':')
13
14 def ipFromPrefix(vifibnet, prefix, prefix_len):
15 prefix = bin(int(prefix))[2:].rjust(prefix_len, '0')
16 ip_t = (vifibnet + prefix).ljust(128, '0')
17 return ipFromBin(ip_t)