From f4eec09a414157b423ac4790dfe22bc09e55bcdf Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Mon, 18 Apr 2022 10:42:35 -0400 Subject: [PATCH] ADd a sample for converting mac to lla --- misc/mac2lla.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 misc/mac2lla.py diff --git a/misc/mac2lla.py b/misc/mac2lla.py new file mode 100644 index 00000000..595f9698 --- /dev/null +++ b/misc/mac2lla.py @@ -0,0 +1,12 @@ +def mac_to_lladdr(mac): + macpieces = [] + mac = mac.replace('-', ':') + for byte in mac.split(':'): + macpieces.append(int(byte, 16)) + macpieces[0] = macpieces[0] ^ 2 + llapieces = [(macpieces[0] << 8) + macpieces[1], (macpieces[2] << 8) + 0xff, 0xfe00 + macpieces[3], (macpieces[4] << 8) + macpieces[5]] + return 'fe80::{:x}:{:x}:{:x}:{:x}'.format(*llapieces) + +if __name__ == '__main__': + import sys + print(mac_to_lladdr(sys.argv[1]))