25
loading...
This website collects cookies to deliver better user experience
A media access control address (MAC address) is a unique identifier assigned to a network interface controller (NIC) for use as a network address in communications within a network segment. MAC addresses are primarily assigned by device manufacturers, and are therefore often referred to as the burned-in address, or as an Ethernet hardware address, hardware address, or physical address.
import sys
from requests import get
class Macpyoui:
def __init__(self, api):
self.api = api
site = "https://api.macvendors.com/"
data = Macpyoui(site)
macaddress = input("Please enter the MAC address: ")
Macpyoui
. This is going to allow us to call our information. __init__
and added the arguments self
and api
.self.api
as api
.site
- This is the website that we will be sending the MAC address.data
- Here we create a variable called data and assign the argument site
to the class Macpyoui
. This will allow me to call it back in a function.macaddress
- We create a variable here called macaddress
and we ask the person running the script what the MAC address is with the input
function and we add the string inside it asking about the MAC address.def searchmac():
macsend = data.api + macaddress
vendorsearch = get(macsend).text
if "Not Found" in vendorsearch:
print("MAC address not found.")
elif len(sys.argv) == 1:
print("No MAC address entered.")
else:
print(vendorsearch)
def searchmac():
searchmac
macsend = data.api + macaddress
macsend
. data.api + macaddress
. data.api
which is asking for the website. data
in data.api
is the class Macpyoui
being called and the .api
is asking for the website in the class. As for macaddress
, this is what the user provides and we combine then with the +
. So written out it would look like https://api.macvendors.com/
+ mac address
vendorsearch = get(macsend).text
vendorsearch
to use the get
request and send the MAC address under the argument macsend
. We make sure to convert it into simple text with .text
at the end.
if "Not Found" in vendorsearch:
print("MAC address not found.")
elif len(sys.argv) == 1:
print("No MAC address entered.")
else:
print(vendorsearch)
if
statements to see what information is entered.
if "Not Found" in vendorsearch:
print("MAC address not found.")
Not Found
, we print out MAC address not found
.
elif len(sys.argv) == 1:
print("No MAC address entered.")
No MAC address entered
.else:
print(vendorsearch)
if __name__ == "__main__":
searchmac()
~ ❯ python3 macpy.py
Please enter the MAC address: F4BD9E
Cisco Systems, Inc
~ ❯ python3 macpy.py
Please enter the MAC address:
MAC address not found.
~ ❯ python3 macpy.py
Please enter the MAC address:
No MAC address entered
import sys
from requests import get
__version__ = "1.0"
class Macpyoui:
def __init__(self, api):
self.api = api
site = "https://api.macvendors.com/"
data = Macpyoui(site)
macaddress = input("Please enter the MAC address: ")
def searchmac():
macsend = data.api + macaddress
vendorsearch = get(macsend).text
if "Not Found" in vendorsearch:
print("MAC address not found.")
elif len(sys.argv) == 1:
print("No MAC address entered.")
else:
print(vendorsearch)
if __name__ == "__main__":
searchmac()