Credentials: login details

credentials.py implements two classes for managing radio login credentials:

Usage Examples:

Contents of ‘list_ip_addresses.txt’
username = admin
password = adminpassw
192.168.0.0/28
Code example
>>> from batchscanner.credentials import Credentials
>>> creds = Credentials(filename='list_ip_addresses.txt')
>>> for batch in creds.get_batches(5):
        print(batch)
Reading credentials from 'list_ip_addresses.txt'
Read a total of 14 credentials
5 Credentials: from 192.168.0.1 to 192.168.0.5
5 Credentials: from 192.168.0.6 to 192.168.0.10
4 Credentials: from 192.168.0.11 to 192.168.0.14

>>> print(batch[-1])
Credential(192.168.0.14, admin, adminpassw)

Class Information:

class batchscanner.credentials.Credentials(items=None, *, text_to_parse=None)

A sequence of Credential, sorted by IP address, and without any duplicates

__init__(items=None, *, text_to_parse=None)

Initialises an instance of the class.

Parameters:

There are 2 ways to initialise Credentials:

  1. If text_to_parse is provided (usually by reading the contents of a config file) then parse the text to obtain:

    • Login credentials: username and password (example below) If omitted, the defaults are ‘admin’/’admin’.

    • A range of IP addresses. Can be any number of the following, each on a new line:
      • A single IP address

      • A range of IP addresses: start and end addresses separated by a hyphen

      • A subnet, with a forward slash denoting the number of subnet bits

    Here is an example content for the input file:

    username = my_user_name
    password = my_password
    192.168.0.100
    192.168.0.101
    10.11.12.1 - 10.11.12.200
    10.10.10.0/24
    192.168.100.0/23
    

    This would result in a total of 1+1+200+254+510 IP addresses.

  2. Alternatively, If text_to_parse is None, then items can be either a single Credential or a sequence of Credential. This option is added in order to implement __getitem__(), and hence the abc.Sequence protocol.

get_batches(batch_size=1000)

A generator method which yields batches at a time, where each batch is a list of Credential. In each batch, the length of the returned list is batch_size, except possibly for the last batch which may be shorter (remainder).

Parameters:

batch_size (int) – Number of Credential in each batch (defaults to 1000)

Returns:

A list of Credential

Return type:

Generator[List[Credential]]

class batchscanner.credentials.Credential(ip_addr, username='admin', password='admin')

A Dataclass for storing radio’s login credentials: IP address, username, and password.

__init__(ip_addr, username='admin', password='admin')
ip_addr: IPv4Address

IP Address of radio

password: str = 'admin'

Password to log into radio

username: str = 'admin'

Username to log into radio