Skip to content
Related Articles

Related Articles

Python script to get device vendor name from MAC Address

View Discussion
Improve Article
Save Article
Like Article
  • Last Updated : 29 Dec, 2020

Prerequisite: Python Requests

A MAC address is a unique identity of a network interface that is used to address the device in a Computer Network.

What does MAC Address consist of?

A MAC address is made up of 12 hexadecimal digits, 6 octets separated by ‘:’. There are 6 octets in a MAC address. In the first half, the manufacturer info is stored.


How do we get the Manufacturer details?

For this article, we will be using an API that will fetch the MAC Address for us. We will use a Python script to automate the fetching process so that we can use it later in the Softwares and websites that may require this functionality.

We will use requests module to work with this API.

Below is the implementation.


import requests
import argparse
print("[*] Welcome")
# Function to get the interface name
def get_arguments():
    # This will give user a neat CLI
    parser = argparse.ArgumentParser()
    # We need the MAC address
    parser.add_argument("-m", "--macaddress",
                        help="MAC Address of the device. "
    options = parser.parse_args()
    # Check if address was given
    if options.mac_address:
        return options.mac_address
        parser.error("[!] Invalid Syntax. "
                     "Use --help for more details.")
def get_mac_details(mac_address):
    # We will use an API to get the vendor details
    # Use get method to fetch details
    response = requests.get(url+mac_address)
    if response.status_code != 200:
        raise Exception("[!] Invalid MAC Address!")
    return response.content.decode()
# Driver Code
if __name__ == "__main__":
    mac_address = get_arguments()
    print("[+] Checking Details...")
        vendor_name = get_mac_details(mac_address)
        print("[+] Device vendor is "+vendor_name)
        # Incase something goes wrong
        print("[!] An error occured. Check "
              "your Internet connection.")

Save this code as We can use ‘-h’ or ‘–help’ to see the help on how to run this script from the terminal.

Output : 

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!