Skip to content

Instantly share code, notes, and snippets.

@ffr4nz
Created May 24, 2013 11:10
Show Gist options
  • Save ffr4nz/5642761 to your computer and use it in GitHub Desktop.
Save ffr4nz/5642761 to your computer and use it in GitHub Desktop.
provides a MAC address from the multicast MAC created by IANA. With a total of 66 111 possible MACs, the MAC can be random if the parameter is omitted or is zero. Also, you can obtain a MAC by index within the range 1-66111. Used over scapy-2.1.0.
multicastList = ["01:00:5E:00:00:00","01:00:5E:7F:FF:FF","01:00:5E:80:00:00",
"01:00:5E:8F:FF:FF","01:00:5E:90:00:00","01:00:5E:FF:FF:FF","01:80:C2:00:00:00",
"09:00:02:04:00:01","09:00:02:04:00:02","09:00:09:00:00:01","09:00:09:00:00:01",
"09:00:09:00:00:04","09:00:1E:00:00:00","09:00:2B:00:00:00","09:00:2B:00:00:01",
"09:00:2B:00:00:02","09:00:2B:00:00:03","09:00:2B:00:00:04","09:00:2B:00:00:05",
"09:00:2B:00:00:06","09:00:2B:00:00:07","09:00:2B:00:00:0F","09:00:2B:00:00:10",
"09:00:2B:00:00:11","09:00:2B:00:00:12","09:00:2B:00:00:13","09:00:2B:00:00:14",
"09:00:2B:00:00:15","09:00:2B:00:00:16","09:00:2B:00:00:17","09:00:2B:00:00:18",
"09:00:2B:00:00:19","09:00:2B:00:00:1A","09:00:2B:00:00:1B","09:00:2B:00:00:1C",
"09:00:2B:00:00:1D","09:00:2B:00:00:1E","09:00:2B:00:00:1F","09:00:2B:01:00:00",
"09:00:2B:01:00:01","09:00:2B:02:00:00","09:00:2B:02:01:00","09:00:2B:02:01:01",
"09:00:2B:02:01:02","09:00:2B:04:00:00","09:00:2B:23:00:00","09:00:4E:00:00:02",
"09:00:56:00:00:00","09:00:56:FE:FF:FF","09:00:56:FF:00:00","09:00:56:FF:FF:FF",
"09:00:77:00:00:01","09:00:7C:02:00:05","09:00:7C:05:00:01","0D:1E:15:BA:DD:06",
"AB:00:00:01:00:00","AB:00:00:02:00:00","AB:00:00:03:00:00","AB:00:00:04:00:00",
"AB:00:00:05:00:00","AB:00:03:FF:FF:FF","AB:00:03:00:00:00","CF:00:00:00:00:00",
"09:00:2B:03:xx:xx","AB:00:04:00:xx:xx","AB:00:04:01:xx:yy"]
class GetMulticastMAC(RandMAC):
"""
------------------------
GetMulticastMAC(Index) - For use in fuzzing probes.
--------------------------------------------------
Get a multicast MAC from the list generated by IANA (http://www.iana.org/assignments/ethernet-numbers)
"""
def __init__(self, Index=0):
self.randMac = None
self.indexMac = None
self.mac = ()
template = "ff:ff:ff:ff:ff:ff"
if Index == 0:
rn = RandNum(0,66111)
if 0 self.randMac = multicastList[rn]
elif 63 template = multicastList[63]
elif 319 template = multicastList[64]
elif 575 template = multicastList[65]
template = template.split(":")
for i in range(6):
if template[i] == "xx" and template[i-1] != "xx":
v = RandByte()
elif template[i] == "xx" and template[i-1] == "xx":
v = v
elif template [i] == "yy":
v = RandByte()
else:
v = int(template[i],16)
self.mac += (v,)
else:
if 0 self.indexMac = multicastList[Index]
if 63 template = multicastList[63]
template = template.split(":")
relativeIndex = Index - 63
for i in range(6):
if template[i] == "xx":
v = int(hex(relativeIndex).split('x')[1],16)
else:
v = int(template[i],16)
self.mac += (v,)
if 319 template = multicastList[64]
template = template.split(":")
relativeIndex = Index - 319
for i in range(6):
if template[i] == "xx":
v = int(hex(relativeIndex).split('x')[1],16)
else:
v = int(template[i],16)
self.mac += (v,)
if 575 template = multicastList[65]
relativeIndex = Index - 575
template = template.split(":")
macof = str("%04X" % relativeIndex)
for i in range(6):
if template[i] == "xx":
v = int(macof[0] + macof[1],16)
elif template[i] == "yy":
v = int(macof[2] + macof[3],16)
else:
v = int(template[i],16)
self.mac += (v,)
def _fix(self):
if self.randMac:
return self.randMac
elif self.indexMac:
return self.indexMac
else:
return "%02x:%02x:%02x:%02x:%02x:%02x" % self.mac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment