Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import sys
- if sys.version_info<(2,6,0):
- print "Python 2.6 or higher required"
- sys.exit()
- if len(sys.argv)!=2:
- print "Usage: mcastmac.py <MCAST IP ADDRESS>"
- sys.exit()
- ipoctets=sys.argv[1].rsplit(".")
- if int(ipoctets[0])<224 or int(ipoctets[0])>239 or int(ipoctets[1])>255 or int(ipoctets[2])>255 or int(ipoctets[3])>255:
- print "Not valid multicast IP address"
- sys.exit()
- def oct2hex(octet,octetnumber):
- if octetnumber==3 or octetnumber==4:
- if int(octet)<=15:
- macoctet="0"+hex(int(octet)).lstrip("0x")
- else:
- macoctet=hex(int(octet)).lstrip("0x")
- if octetnumber==2:
- if int(octet)<=15:
- macoctet="0"+hex(int(octet)).lstrip("0x")
- elif int(octet)>15 and int(octet)<128:
- macoctet=hex(int(octet)).lstrip("0x")
- else:
- macoctet=hex(int(bin(int(octet))[-7:],2)).lstrip("0x")
- if len(macoctet)!=2:
- macoctet="0"+macoctet
- return macoctet
- macoctet4=oct2hex(ipoctets[1],2)
- macoctet5=oct2hex(ipoctets[2],3)
- macoctet6=oct2hex(ipoctets[3],4)
- print sys.argv[1], "01:00:5e:"+macoctet4+":"+macoctet5+":"+macoctet6
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement