Skip to content

Instantly share code, notes, and snippets.

@jossef
Last active August 29, 2015 14:26
Show Gist options
  • Select an option

  • Save jossef/885944214de79ae15723 to your computer and use it in GitHub Desktop.

Select an option

Save jossef/885944214de79ae15723 to your computer and use it in GitHub Desktop.
wireshark mac manuf to json file
import json
def main():
contents = open('json_data_raw.json').read()
response = json.loads(contents)
items = {k.replace('-','').replace(':','').lower():v for k, v in response.iteritems()}
short_macs = filter(lambda x: len(x[0]) == 6, items.iteritems())
long_macs = filter(lambda x: len(x[0]) == 10, items.iteritems())
data = {
'mac_prefixes': dict(short_macs),
'extended_mac_prefixes': dict(long_macs)
}
json_string = json.dumps(data)
with open('indexed_mac_addresses_no_sort.json','w') as f:
f.write(json_string)
if __name__ == '__main__':
main()
import requests
import re
import json
def main():
response = dict()
r = requests.get('https://code.wireshark.org/review/gitweb?p=wireshark.git;a=blob_plain;f=manuf', verify=False)
lines = r.text.splitlines()
for line in lines:
try:
line = line.encode('ascii', 'ignore')
if line.startswith('#'):
continue
splitted = line.split('\t')
mac_prefix = splitted[0]
mac_prefix = mac_prefix.strip()
is_valid_mac_prefix = re.match('^([0-9|A-F|a-f]{2}[:|-]){2}([0-9|A-F|a-f]{2})$',mac_prefix)
is_valid_mac_mask = re.match('^([0-9|A-F|a-f]{2}[:|-]){5}(00\/36)$',mac_prefix)
if not is_valid_mac_prefix:
if is_valid_mac_mask:
mac_prefix = mac_prefix.replace(':00/36', '')
else:
continue
splitted = splitted[1].split('#')
name = splitted[0]
name = name.strip()
description = name
if len(splitted) > 1 :
description = splitted[1]
description = description.strip()
if not name:
continue
response[mac_prefix] = {'name':name, 'description':description}
except Exception as e:
pass
return response
if __name__ == '__main__':
data = main()
json_string = json.dumps(data)
with open('json_data_raw.json','w') as f:
f.write(json_string)
@jossef

jossef commented Aug 3, 2015

Copy link
Copy Markdown
Author

Scraping utility for wireshark's mac mapping file
https://code.wireshark.org/review/gitweb?p=wireshark.git;a=blob_plain;f=manuf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment