From 828b68ab34b8437f11f8d702913292b84d5418c6 Mon Sep 17 00:00:00 2001 From: Nils Schneider Date: Sun, 23 Dec 2012 23:08:58 +0100 Subject: [PATCH] add hostid module with mac_to_hostid function --- hostid.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 hostid.py diff --git a/hostid.py b/hostid.py new file mode 100644 index 0000000..2b4038e --- /dev/null +++ b/hostid.py @@ -0,0 +1,13 @@ +import re +from functools import reduce + +def mac_to_hostid(mac): + int_mac = list(map(lambda x: int(x, 16), mac.split(":"))) + int_mac[0] ^= 2 + bytes = map(lambda x: "%02x" % x, int_mac[0:3] + [0xff, 0xfe] + int_mac[3:]) + return reduce(lambda a, i: + [a[0] + ("" if i == 0 else ":") + a[1] + a[2]] + a[3:], + range(0, 4), + [""] + list(bytes) + ) +