Skip to content

Instantly share code, notes, and snippets.

@gawen
Created November 26, 2018 11:40
Show Gist options
  • Save gawen/0c73e27b6159c248749b3a4cbf9b6e72 to your computer and use it in GitHub Desktop.
Save gawen/0c73e27b6159c248749b3a4cbf9b6e72 to your computer and use it in GitHub Desktop.
Calculate all MAC addresses between two MAC addresses.
# Everything prefixed by a # is a comment, and therefore is read by human and
# ignored by the machine
# First MAC address of the batch
FIRST_MAC = "E08E3C3923A2"
# Last MAC address of the batch
LAST_MAC = "e08e3c393234"
# we convert the first and last macs in decimals. To do so, we call 'int' with
# two arguments: the mac addresses and 16, because hexa (in hexadecimals) is 16
# in greek
first_decimals = int(FIRST_MAC, 16)
last_decimals = int(LAST_MAC, 16)
# We set a variable 'i' to the first MAC
i = first_decimals
# And while i is less than the last MAC ...
while i <= last_decimals:
# ... convert i into its hexadecimal form ...
i_hexa = hex(i)[2:]
# ... print the hexadecimal form of i to the screen ...
print(i_hexa)
# ... increment i ...
i = i + 1
# ... and you loop back to while
# Now i reached the last MAC address, we can quit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment