Rob
Rob

Reputation: 111

Increase / Decrease Mac Address in Python from String

I have a mac address in string form. I am interested in taking the Mac string and increasing / decreasing it by 1 value while keeping the integrity of Hex in Python

Ex: 000000001F

-1: 000000001E +1: 0000000020

Upvotes: 3

Views: 3786

Answers (1)

Thomas B.
Thomas B.

Reputation: 2296

Parse it, change it, print it!

def change_mac(mac, offset)
    return "{:012X}".format(int(mac, 16) + offset)

Upvotes: 11

Related Questions