Python script to get device vendor name from MAC Address
Last Updated :
07 Sep, 2022
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.
Python3
import requests
import argparse
print ( "[*] Welcome" )
def get_arguments():
parser = argparse.ArgumentParser()
parser.add_argument( "-m" , "--macaddress" ,
dest = "mac_address" ,
help = "MAC Address of the device. "
)
options = parser.parse_args()
if options.mac_address:
return options.mac_address
else :
parser.error( "[!] Invalid Syntax. "
"Use --help for more details." )
def get_mac_details(mac_address):
response = requests.get(url + mac_address)
if response.status_code ! = 200 :
raise Exception( "[!] Invalid MAC Address!" )
return response.content.decode()
if __name__ = = "__main__" :
mac_address = get_arguments()
print ( "[+] Checking Details..." )
try :
vendor_name = get_mac_details(mac_address)
print ( "[+] Device vendor is " + vendor_name)
except :
print ( "[!] An error occurred. Check "
"your Internet connection." )
|
Save this code as macdetails.py. We can use ‘-h’ or ‘–help’ to see the help on how to run this script from the terminal.
Output :
Share your thoughts in the comments
Please Login to comment...