random_mac package

random_mac.classifier module

This module contains classifier-related functions.

random_mac.classifier.make()[source]

Retrieve a classifier.

Returns:A classifier.
Return type:sklearn classifier
random_mac.classifier.train(classifier, data, labels)[source]

Train a classifier.

Parameters:
  • classifier (sklearn classifier) – The classifier to train.
  • data (numpy array) – The data with which to train the classifier.
  • labels (numpy array) – The labels with which to train the classifier.
Returns:

The trained classifier.

Return type:

sklearn classifier

random_mac.classifier.test(classifier, data, labels)[source]

Test a classifier.

Parameters:
  • classifier (sklearn classifier) – The classifier to test.
  • data (numpy array) – The data with which to test the classifier.
  • labels (numpy array) – The labels with which to test the the classifier.
Returns:

The results of the test.

Return type:

float

random_mac.classifier.save(classifier, file='random-mac-classifier.pickled')[source]

Save (pickle) a classifier.

Parameters:
  • classifier (sklearn classifier) – The classifier to save.
  • file (str) – The name of the destination file.
random_mac.classifier.restore(file='random-mac-classifier.pickled')[source]

Restore (unpickle) a classifier.

Parameters:file (str) – The name of the source file.
Returns:The restored (unpickled) classifier.
Return type:sklearn classifier
random_mac.classifier.is_random_mac(classifier, address)[source]

Determine whether a MAC address is random or non-random.

Parameters:
  • classifier (sklearn classifier) – The classifier to use.
  • address (str (hexadecimal)) – The address to test.
Returns:

Whether the given MAC address is random (True) or non-random (False).

Return type:

bool

random_mac.dataset module

This module contains dataset-related functions.

random_mac.dataset.get_ieee_assignments(file)[source]

Retrieve OUIs and CIDs.

Parameters:file (str) –

The name of a file with information on OUIs and CIDs assigned by the IEEE.

Typical names are oui.csv and cid.csv.

Returns:A list of 24-bit OUIs or CIDs assigned by the IEEE.
Return type:list
random_mac.dataset.make_hexadecimal_digit_strings(assignments)[source]

Make hexadecimal strings based upon OUIs and CIDs.

Parameters:assignments (list) – A list of 24-bit OUIs or CIDs assigned by the IEEE.
Returns:A list of 48-bit hexadecimal strings, where each string is the concatenation of a 24-bit OUI/CID and 24 random bits.
Return type:list
random_mac.dataset.make_random_hexadecimal_digit_strings(number)[source]

Make random hexadecimal strings.

Parameters:number (int) – The number of hexadecimal strings to make.
Returns:A list of 48-bit hexadecimal strings, where each string is 48 random bits.
Return type:list
random_mac.dataset.get_mac_features(digit_string)[source]

Retrieve the features of a MAC address.

Parameters:digit_string (str) – A 48-bit hexadecimal string with which to instantiate MediaAccessControlAddress.
Returns:An eight-tuple with the features of a MAC address.

The features are type, has_oui, has_cid, is_broadcast, is_multicast, is_unicast, is_uaa, and is_laa.

Return type:tuple
random_mac.dataset.get_features(digit_strings)[source]

Retrieve the features of MAC addresses.

Parameters:digit_strings (list) – A list of 48-bit hexadecimal strings.
Returns:A list of tuples, where each tuple contains the features of a MAC address.
Return type:list
random_mac.dataset.normalize_features(features)[source]

Normalize the features of MAC addresses.

Parameters:features (list) – A list of tuples, where each tuple contains the features of a MAC address.
Returns:A numpy array with the normalized features of MAC addresses, where normalization means replacing non-numeric with numeric values and converting the container from a list to a numpy array.
Return type:numpy array
random_mac.dataset.make_labels(value, number)[source]

Make labels for training and testing of a binary classifier.

Parameters:
  • value (int) – The label, where 0 means a non-random MAC addresses and 1 means a random MAC address.
  • number (int) – The number of labels.
Returns:

A list with the given number of the given label.

Return type:

list

random_mac.dataset.normalize_labels(labels)[source]

Normalize labels.

Parameters:labels (list) – A list of labels.
Returns:A numpy array with normalized labels, where normalization means converting the container from a list to a numpy array.
Return type:numpy array
random_mac.dataset.make(multiple, oui_file='./oui.csv', cid_file='./cid.csv')[source]

Make a dataset for training and testing purposes.

Parameters:
  • multiple (int) – The number of random MAC addresses to create for every non-random MAC address.
  • oui_file (str) – The name of the file with OUIs assigned by the IEEE.
  • cid_file (str) – The name of the file with CIDs assigned by the IEEE.
Returns:

A tuple with data (features) and labels.

Return type:

tuple

Module contents

Use machine learning to identify randomly-generated MAC addresses.

random_mac.is_random_mac(classifier, address)[source]

Determine whether a MAC address is random or non-random.

Parameters:
  • classifier (sklearn classifier) – The classifier to use.
  • address (str (hexadecimal)) – The address to test.
Returns:

Whether the given MAC address is random (True) or non-random (False).

Return type:

bool