![]() Note that the purpose of the hex() function is to produce a hexadecimal integer literal (a string that can be used in Python source code), which is why it returns a hex value with the 0x prefix. # Remove/slice the '0x' off the begining from using hex(). # use xor of 02 on the 2nd most significant hex char. # cast the hex string to an base-16 int for math safety. ![]() # remove the most common macaddr delimiters, dots, dashes, etc. #!/usr/bin/pythonĬonvert mac addr to ipv6 link local (rfc 4862) I'm using python 2.7, but my Linux distro is soon to switch to 3.x. ![]() is the code future proof to 3.4 python?Įspecially with casting a string to an int, and finally back to hex, seems overly weird.Īlso, I did recently discover some IP related factory functions, but so far I've not discovered any builtin way of doing this.is there a more pythonic way of doing this?.One of the ways I learn a new scripting language is to implement a subroutine to convert a network MAC addr into the IPv6 link-local address, as described in RFC 4862. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |