Commit 139ec4f0 authored by Daniel STAN's avatar Daniel STAN

bin fe80

parent 7d8c3c6d
#!/usr/bin/python3
# Petit script à deux balles qui renvoie l'ipv6 de lien local à partir de la
# mac (eui64). L'intérêt est de pouvoir rapidement "pinguer une mac"
# Par exemple:
# | $ ping6 $(fe80 00:19:bb:3c:4f:76)%eth0
# | PING fe80::219:bbff:fe3c:4f76%eth0(fe80::219:bbff:fe3c:4f76) 56 data bytes
# | 64 bytes from fe80::219:bbff:fe3c:4f76: icmp_seq=1 ttl=64 time=0.441 ms
import sys, re
HEX = r'([0-9a-zA-Z]{1,2})'
SEP = r'[^0-9a-zA-Z]?'
MAC = (HEX + SEP)*5 + HEX
if len(sys.argv) < 2:
print("Donne une mac")
sys.exit(1)
match = re.match(MAC, sys.argv[1])
if match is None:
print("Mac non reconnue")
sys.exit(2)
mac = [ int(match.group(i), 16) for i in range(1,7) ]
mac[0] = mac[0] ^ 2
mac.insert(3, 0xfe)
mac.insert(3, 0xff)
end_ip = [ (mac[2*i]*0x100 + mac[2*i+1]) for i in range(0,4) ]
print("fe80::%s" % ":".join("%x" % s for s in end_ip))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment