MAC Address to Vendors

This is a simple python script that utilizes MAC to vendor API from macvendors.com to get the statistics of different devices connected to a network, especially on guest wifi networks.

The mac addresses are copied to a text file. The script reads each line from the text file at a time and submit the API requests to get corresponding vendor name.

root@myhost~# cat macfile.txt
c0bd-d151-b49b
a4d1-d2d5-d40a
98e7-f5e2-c706
c0cc-f870-c76a
7081-ebac-b6f5
d4f4-6fa7-afb0
0402-1f02-0431
d0fc-cc5b-74f8
e8b4-c833-faf6

The python script uses request library for processing http requests. No registration or API key is required for up to 1,000 requests per day at 1 request per second. In this example I have added 1 second delay in the script after each request. For higher limits, please checkout their various plans.

MAC addresses can be in any of the following formats.

  • 00-11-22-33-44-55
  • 00:11:22:33:44:55
  • 00.11.22.33.44.55
  • 001122334455
  • 0011.2233.4455

File getmac.py

#!/usr/bin/python
import requests
import sys
import time

URL= 'https://api.macvendors.com/'

def main():
        session = requests.Session()
        myfile = open("macfile.txt","r")
        data = ""
        lines = myfile.readlines()
        for line in lines:
                #print (line)
                response = session.get(URL+line,headers={'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)'})
                print "MAC:" +line.replace('\n', '') +" :" + (response.text)
                time.sleep(1)

if __name__ == '__main__':# main method
   main()

You can execute the script as follows

root@myhost ~# python getmac.py
MAC:c0bd-d151-b49b :SAMSUNG ELECTRO-MECHANICS(THAILAND)
MAC:a4d1-d2d5-d40a :Apple, Inc.
MAC:98e7-f5e2-c706 :HUAWEI TECHNOLOGIES CO.,LTD
MAC:c0cc-f870-c76a :Apple, Inc.
MAC:7081-ebac-b6f5 :Apple, Inc.
MAC:d4f4-6fa7-afb0 :Apple, Inc.
MAC:0402-1f02-0431 :HUAWEI TECHNOLOGIES CO.,LTD
MAC:d0fc-cc5b-74f8 :Samsung Electronics Co.,Ltd
MAC:e8b4-c833-faf6 :Samsung Electronics Co.,Ltd
MAC:5cf7-e6dd-fd79 :Apple, Inc.
MAC:90b0-edb5-f9b2 :Apple, Inc.
MAC:8cf5-a3e0-d8bf :SAMSUNG ELECTRO-MECHANICS(THAILAND)

 

Please follow and like us: