Skip to content

Commit c7ac8c1

Browse files
committed
* updated README, use from import instead of import for examples. both work
* added new function for another_same_vid(). generates a new mac address based on same VID as a provided MAC * Bugfix, changed "none" to None in the lookup table. This was changed in the functions, but some reason, not in the lookup table
1 parent a8bc6cc commit c7ac8c1

3 files changed

Lines changed: 36 additions & 19 deletions

File tree

README.md

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,51 +28,57 @@ Usage
2828
Import and set up an object.
2929

3030
```
31-
import generate_mac
32-
g = generate_mac.generate_mac
31+
from generate_mac import generate_mac
3332
```
3433

3534
Procedurely generated Vendor and Host bytes. Checks for broadcast bit
3635

3736
```
38-
g.total_random()
39-
'12:7E:C4:B5:F1:8E'
37+
generate_mac.total_random()
38+
'7E:CD:60:1E:AC:6E'
4039
```
4140

4241
Read Vendor bytes from random line in a file. This has to be formated the same
4342
as wireshark's manuf file.
4443
```
45-
g.vid_file_random('/usr/share/wireshark/manuf')
46-
'00:55:DA:10:FB:D8'
44+
generate_mac.vid_file_random('/usr/share/wireshark/manuf')
45+
'70:B3:D5:C5:40:49'
4746
```
4847

4948
Read from a manuf file like above, but find Vendor bytes belonging to a specific
5049
vendor, by name.
5150
```
52-
g.vid_file_vendor('/usr/share/wireshark/manuf', 'Apple')
53-
'94:0C:98:BC:74:1C'
51+
generate_mac.vid_file_vendor('/usr/share/wireshark/manuf', '3Com')
52+
'00:06:8C:C7:3F:93'
5453
```
5554

5655
Provide the vendor bytes in a string. Generate Host bytes only
5756
```
58-
g.vid_provided('AA:BB:CC')
59-
'AA:BB:CC:B8:B3:01'
57+
generate_mac.vid_provided('00:06:8C')
58+
'00:06:8C:35:5E:C4'
6059
```
6160

6261
List valid vendor options as a list.
6362
```
64-
g.list_vendors('/usr/share/wireshark/manuf')
63+
generate_mac.list_vendors('/usr/share/wireshark/manuf')
6564
['Vendor1','Vendor2','etc']
6665
```
6766

68-
Check if a MAC address is valid
67+
Check if a MAC address is valid. returns a Bool(True,False)
6968
```
70-
if g.is_mac_address('94:0C:98:BC:74:1C') == True:
71-
print('Valid Ethernet Address')
69+
generate_mac.is_mac_address('00:06:8C:35:5E:C4')
70+
True
71+
7272
```
7373

7474
Get the VID bytes from a MAC address
7575
```
76-
g.get_vid_bytes('94:0C:98:BC:74:1C')
77-
'94:0C:98'
76+
generate_mac.get_vid_bytes('00:06:8C:35:5E:C4')
77+
'00:06:8C'
78+
```
79+
80+
Generate another MAC from the same VID bytes as current MAC
81+
```
82+
generate_mac.another_same_vid('00:06:8C:35:5E:C4')
83+
'00:06:8C:3D:C2:F2'
7884
```

generate_mac/__init__.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class generate_mac():
1212
'36':2,
1313
'32':3,
1414
'28':4,
15-
'none':6,
15+
None:6,
1616
}
1717
def _strip_comments(in_list):
1818
'''Proccesses out comments using # as the comment character'''
@@ -208,14 +208,25 @@ def is_mac_address(mac_address):
208208
return False
209209

210210
def get_vid_bytes(mac_address):
211-
'''return vendor bytes from a given MAC address as a string'''
211+
'''Return vendor bytes from a given MAC address as a string'''
212212
# check if this is a valid mac address
213213
if generate_mac.is_mac_address(mac_address) != True:
214-
raise ValueError(mac_address + ' is not a validi MAC address')
214+
raise ValueError(mac_address + ' is not a valid MAC address')
215215

216216
output = ""
217217
# Grab the first three bytes, this is the VID
218218
mac_bytes = mac_address.split(":")
219219
output = ":".join(mac_bytes[0:3])
220220

221221
return output
222+
223+
def another_same_vid(mac_address):
224+
'''Generate another MAC address from the same VID bytes'''
225+
output = ""
226+
227+
vid_bytes = generate_mac.get_vid_bytes(mac_address)
228+
dev_bytes = generate_mac._gen_rand_bytes(3)
229+
output = vid_bytes + ":" + dev_bytes
230+
output = output.upper()
231+
232+
return output
287 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)