Skip to content

Commit 08727f8

Browse files
committed
new function: get_vid_bytes(). returns VID bytes from valid MAC address,
thows type error if address is incorrect
1 parent d8c6b49 commit 08727f8

3 files changed

Lines changed: 19 additions & 0 deletions

File tree

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,9 @@ Check if a MAC address is valid
7070
if g.is_mac_address('94:0C:98:BC:74:1C') == True:
7171
print('Valid Ethernet Address')
7272
```
73+
74+
Get the VID bytes from a MAC address
75+
```
76+
g.get_vid_bytes('94:0C:98:BC:74:1C')
77+
'94:0C:98'
78+
```

generate_mac/__init__.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,3 +207,16 @@ def is_mac_address(mac_address):
207207
return True
208208
else:
209209
return False
210+
211+
def get_vid_bytes(mac_address):
212+
'''return vendor bytes from a given MAC address as a string'''
213+
# check if this is a valid mac address
214+
if generate_mac.is_mac_address(mac_address) != True:
215+
raise ValueError(mac_address + ' is not a validi MAC address')
216+
217+
output = ""
218+
# Grab the first three bytes, this is the VID
219+
mac_bytes = mac_address.split(":")
220+
output = ":".join(mac_bytes[0:3])
221+
222+
return output
975 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)