def handler(q=False): if q is False: return False request = json.loads(q) if request.get('mac-address'): mac_address = request['mac-address'] else: return False if request.get('config') and request['config'].get('api_key'): api_key = request['config'].get('api_key') else: misperrors['error'] = 'Authorization required' return misperrors api_client = ApiClient(api_key) try: response = api_client.get(mac_address) except exceptions.EmptyResponseException: misperrors['error'] = 'Empty response' return misperrors except exceptions.UnparsableResponseException: misperrors['error'] = 'Unparsable response' return misperrors except exceptions.ServerErrorException: misperrors['error'] = 'Internal server error' return misperrors except exceptions.UnknownOutputFormatException: misperrors['error'] = 'Unknown output' return misperrors except exceptions.AuthorizationRequiredException: misperrors['error'] = 'Authorization required' return misperrors except exceptions.AccessDeniedException: misperrors['error'] = 'Access denied' return misperrors except exceptions.InvalidMacOrOuiException: misperrors['error'] = 'Invalid MAC or OUI' return misperrors except exceptions.NotEnoughCreditsException: misperrors['error'] = 'Not enough credits' return misperrors except Exception: misperrors['error'] = 'Unknown error' return misperrors date_created = \ response.block_details.date_created.strftime('%d %B %Y') if response.block_details.date_created else None date_updated = \ response.block_details.date_updated.strftime('%d %B %Y') if response.block_details.date_updated else None results = { 'results': [{ 'types': ['text'], 'values': { # Mac address details 'Valid MAC address': "True" if response.mac_address_details.is_valid else "False", 'Transmission type': response.mac_address_details.transmission_type, 'Administration type': response.mac_address_details.administration_type, # Vendor details 'OUI': response.vendor_details.oui, 'Vendor details are hidden': "True" if response.vendor_details.is_private else "False", 'Company name': response.vendor_details.company_name, 'Company\'s address': response.vendor_details.company_address, 'County code': response.vendor_details.country_code, # Block details 'Block found': "True" if response.block_details.block_found else "False", 'The left border of the range': response.block_details.border_left, 'The right border of the range': response.block_details.border_right, 'The total number of MAC addresses in this range': response.block_details.block_size, 'Assignment block size': response.block_details.assignment_block_size, 'Date when the range was allocated': date_created, 'Date when the range was last updated': date_updated } }] } return results
df = pd.DataFrame(wigle_wifi) wifiList = list(df['MAC']) #establish client to maclookup client = ApiClient('at_vsEFrkTL6alaO3fzbu3JgaaWnb2j1') #create a dictionary to hold frequency of oui found dict = {} #process the csv, extract the mac for counter, value in enumerate(wifiList): #call maclookup using the mac mac = value print(f'Looking up {mac}') response = client.get(mac) oui = response.vendor_details.oui name = response.vendor_details.company_name #update the data frame by adding the meta data df.loc[:, 'OUI'] = oui df.loc[:, 'NAME'] = name #update dictionary if(oui in dict): dict[oui] += 1 else: dict[oui] = 1 #output the new data frame containing the meta data to csv df.to_csv('output.csv')
from maclookup import ApiClient import logging import os api_key = os.environ['API_KEY'] log_file = os.environ['LOG_FILENAME'] client = ApiClient(api_key) logging.basicConfig(filename=log_file, level=logging.WARNING) print(client.get_raw_data('08EA4026E5DE', 'csv')) print(client.get_vendor('08EA4026E5DE')) response = client.get('08EA4026E5DE') print(response.vendor_details.is_private) print(response.block_details.block_size)
from maclookup import ApiClient import logging client = ApiClient('at_gVL2VUlnXzRjD9mkj70Avd6bqgdkm') logging.basicConfig(filename='myapp.log', level=logging.WARNING) print(client.get_raw_data('00A043AAAAAA', 'json')) print(client.get_vendor('BBA043AAAAAA')) print(client.get('BBA043AAAAAA')) response = client.get('00A043AAAAAA') print(response.vendor_details.is_private) print(response.block_details.date_created)