Data type conversions (Compute MAC addresses)

Source: Internet
Author: User

[Email protected] test1]# vim 19.py//add#!/usr/bin/pythonmacaddr = ' 00:0c:29:d1:6f:e9 ' Prefix_mac = macaddr[:-3]last_ both = Macaddr[-2:]plus_one = Int (last_two, +) + 1new_last_two = Hex (plus_one) [2:]NEW_MAC = Prefix_mac + ': ' + NEW_LAST_TW Oprint new_mac.upper ()///     Prefix_mac--Defines the prefix of the MAC address, to keep the first five bits unchanged [:-3]--from the beginning to the third lowest (the colon is also counted as a)    Last_two--First take the last two bits, [2 :]  from the last second to the end    because the MAC address is 16, you want to convert it to 10 binary--plus_one and then add 1--Get new    and then convert the new 16 binary to 10--sometimes it will print 0x (that means 16 binary)                 --New_last_two--[2:] from the third to the last    New_mac--The new address, is the prefix plus the last calculated two bits, using a colon to connect    upper ()--this function can be lowercase letters into uppercase letters */[[EMA Il protected] test1]# python 19.py00:0c:29:d1:6f:ea    

/* Above is just a script for a MAC address.     when there is something different, you can test it first by entering the Python state,    find a good solution, and then write it in the script.

/*     If the last two bits are 01, 0 will not be displayed after conversion, and 1 will be displayed.    Workaround: */[[email protected] test1]# vim 19.py//add#!/usr/bin/pythonmacaddr = ' 00:0c:29:d1:6f:01 ' Prefix_mac = macaddr[:-3 ]last_two = macaddr[-2:]plus_one = Int (last_two, +) + 1if Plus_one in range:    new_last_two = Hex (plus_one) [2:]
   
    new_last_two = ' 0 ' + new_last_twoelse:    new_last_two = Hex (plus_one) [2:]NEW_MAC = Prefix_mac + ': ' + new_last_twoprint New_mac.upper ()
   

/* If the last two bits is 0 A, then the next one should be B0, but 0 is not able to take the    solution: */[[email protected] test1]# vim 19.py//add#!/usr/bin/pythonmacaddr = ' 00:0c:29:d1:6f:0a ' Prefix_mac = macaddr[:-3]last_two = Macaddr[-2:]plus_one = Int (last_two, +) + 1if Plus_one in range (10) :    new_last_two = Hex (Plus_one) [2:]    new_last_two = ' 0 ' + new_last_twoelse:    new_last_two = Hex (Plus_one) [2:]        If Len (new_last_two) = = 1:            new_last_two = ' 0 ' + New_last_twonew_mac = Prefix_mac + ': ' + new_last_twoprint New_ma C.upper ()

Data type conversions (Compute MAC addresses)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.