1. 程式人生 > >Python 練習題:計算 MAC 地址

Python 練習題:計算 MAC 地址

new 練習 clas 地址 pri color spa pytho bin

#!/usr/bin/env python
#-*- coding:utf-8 -*- 

‘‘‘ 給一個MAC地址加1 ‘‘‘

mac = 52:54:00:e6:b2:0a
prefix_mac = mac[:-2]

last_two = mac.split(:)[-1].lower()
new_last_two = int(last_two, 16) + 1
new_last_two = hex(new_last_two).split(x)[-1]
if len(str(new_last_two)) == 1:
    new_last_two = 0 + new_last_two
new_mac 
= prefix_mac + new_last_two print(new_mac)

Python 練習題:計算 MAC 地址