MCPcopy Index your code
hub / github.com/retspen/webvirtcloud / intToIp

Function intToIp

vrtManager/IPy.py:1097–1126  ·  view source on GitHub ↗

Transform an integer string into an IP address.

(ip, version)

Source from the content-addressed store, hash-verified

1095
1096
1097def intToIp(ip, version):
1098 """Transform an integer string into an IP address."""
1099
1100 # just to be sure and hoping for Python 2.22
1101 ip = long(ip)
1102
1103 if ip < 0:
1104 raise ValueError, "IPs can't be negative: %d" % (ip)
1105
1106 ret = ''
1107 if version == 4:
1108 if ip > 0xffffffffL:
1109 raise ValueError, "IPv4 Addresses can't be larger than 0xffffffff: %s" % (hex(ip))
1110 for l in range(4):
1111 ret = str(ip & 0xffL) + '.' + ret
1112 ip = ip >> 8
1113 ret = ret[:-1]
1114 elif version == 6:
1115 if ip > 0xffffffffffffffffffffffffffffffffL:
1116 raise ValueError, "IPv6 Addresses can't be larger than 0xffffffffffffffffffffffffffffffff: %s" % (hex(ip))
1117 l = '0' * 32 + hex(ip)[2:-1]
1118 for x in range(1, 33):
1119 ret = l[-x] + ret
1120 if x % 4 == 0:
1121 ret = ':' + ret
1122 ret = ret[1:]
1123 else:
1124 raise ValueError, "only IPv4 and IPv6 supported"
1125
1126 return ret
1127
1128
1129def _ipVersionToLen(version):

Callers 5

_printPrefixMethod · 0.85
strCompressedMethod · 0.85
strFullsizeMethod · 0.85
strNetmaskMethod · 0.85
reverseNameMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected