Skip to content
Snippets Groups Projects
Commit d4370abd authored by Phil's avatar Phil
Browse files

Added RandIP6()

parent a4476dae
No related branches found
No related tags found
No related merge requests found
...@@ -240,6 +240,51 @@ class RandMAC(RandString): ...@@ -240,6 +240,51 @@ class RandMAC(RandString):
def _fix(self): def _fix(self):
return "%02x:%02x:%02x:%02x:%02x:%02x" % self.mac return "%02x:%02x:%02x:%02x:%02x:%02x" % self.mac
class RandIP6(RandString):
def __init__(self, ip6template="**"):
self.tmpl = ip6template
self.sp = self.tmpl.split(":")
for i,v in enumerate(self.sp):
if not v or v == "**":
continue
if "-" in v:
a,b = v.split("-")
elif v == "*":
a=b=""
else:
a=b=v
if not a:
a = "0"
if not b:
b = "ffff"
if a==b:
self.sp[i] = int(a,16)
else:
self.sp[i] = RandNum(int(a,16), int(b,16))
self.variable = "" in self.sp
self.multi = self.sp.count("**")
def _fix(self):
done = 0
nbm = self.multi
ip = []
for i,n in enumerate(self.sp):
if n == "**":
nbm -= 1
remain = 8-(len(self.sp)-i-1)-len(ip)+nbm
if "" in self.sp:
remain += 1
if nbm or self.variable:
remain = random.randint(0,remain)
for j in range(remain):
ip.append("%04x" % random.randint(0,65535))
elif not n:
ip.append("")
else:
ip.append("%04x" % n)
if len(ip) == 9:
ip.remove("")
return ":".join(ip)
class RandOID(RandString): class RandOID(RandString):
def __init__(self, fmt=None, depth=RandNumExpo(0.1), idnum=RandNumExpo(0.01)): def __init__(self, fmt=None, depth=RandNumExpo(0.1), idnum=RandNumExpo(0.01)):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment