File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -19,6 +19,9 @@ Random device bytes will be generated.
1919
2020** list_vendors(_ file_ )** - return a python list [ ] with valid vendors
2121
22+ ** is_mac_address(_ mac_ )** - Takes a string, and checks if it is a valid Ethernet
23+ MAC address. returns True or False(bool type)
24+
2225Usage
2326-----
2427
@@ -61,3 +64,9 @@ List valid vendor options as a list.
6164g.list_vendors('/usr/share/wireshark/manuf')
6265['Vendor1','Vendor2','etc']
6366```
67+
68+ Check if a MAC address is valid
69+ ```
70+ if g.is_mac_address('94:0C:98:BC:74:1C') == True:
71+ print('Valid Ethernet AAddress')
72+ ```
Original file line number Diff line number Diff line change @@ -190,3 +190,20 @@ def list_vendors(vid_file):
190190 '''Returns a list[] of valid ETH Vendors that can be used with vid_file_vendor()'''
191191 file_lines = generate_mac ._read_vid_file (vid_file )
192192 return list (generate_mac ._valid_vendors )
193+
194+ def is_mac_address (mac_address ):
195+ '''Test if a given string is a valid Ethernet MAC address. return True or False'''
196+ try :
197+ mac_bytes = mac_address .split (":" )
198+ except :
199+ return False
200+ if len (mac_bytes ) != 6 :
201+ return False
202+
203+ # First Octet needs to be odd.
204+ mac_byte_bcast = mac_bytes [0 ][1 ]
205+ mac_byte_bcast = mac_byte_bcast .upper ()
206+ if mac_byte_bcast in generate_mac ._valid_bcast_char :
207+ return True
208+ else :
209+ return False
You can’t perform that action at this time.
0 commit comments