View difference between Paste ID: RqjBbz74 and G5CQ9Wmc
SHOW: | | - or go back to the newest paste.
1
#!/usr/bin/python
2
import sys
3
if sys.version_info<(2,6,0):
4
  print "Python 2.6 or higher required"
5
  sys.exit()
6
7
if len(sys.argv)!=2:
8
  print "Usage: mcastmac.py <MCAST IP ADDRESS>"
9
  sys.exit()
10
ipoctets=sys.argv[1].rsplit(".")
11
12
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:
13-
    if int(octet,10)>255:
13+
  print "Not valid multicast IP address"
14-
        print "IP octet",octetnumber,"is bigger than 255"
14+
15-
        sys.exit()
15+
16
def oct2hex(octet,octetnumber):
17
    if octetnumber==3 or octetnumber==4:
18
        if int(octet)<=15:
19
            macoctet="0"+hex(int(octet)).lstrip("0x")
20
        else:
21
            macoctet=hex(int(octet)).lstrip("0x")
22
    if octetnumber==2:
23
        if int(octet)<=15:
24
            macoctet="0"+hex(int(octet)).lstrip("0x")
25
        elif int(octet)>15 and int(octet)<128:
26
            macoctet=hex(int(octet)).lstrip("0x")
27
        else:
28
            macoctet=hex(int(bin(int(octet))[-7:],2)).lstrip("0x")
29
            if len(macoctet)!=2:
30
                macoctet="0"+macoctet
31
            
32
    return macoctet
33
34
macoctet4=oct2hex(ipoctets[1],2)
35
macoctet5=oct2hex(ipoctets[2],3)
36
macoctet6=oct2hex(ipoctets[3],4)
37
38
print sys.argv[1], "01:00:5e:"+macoctet4+":"+macoctet5+":"+macoctet6