sirup.utils

Classes

RotationList

Custom list for IP rotation.

Functions

get_ip([echo, config_file])

Query the current IP address of the computer.

lookup_strings_in_list(strings_to_check, list_of_strings)

Scan a list of strings for presence of one or multiple strings in the same element.

check_connection(log_file, timeout, pwd[, waiting_time])

Wait and test for established connection until timeout.

sudo_read_file(file[, pwd])

Read a file with root permission to a list.

check_password(pwd)

Run simple command to see if password is correct

list_files_with_full_path(directory[, rule])

Collect all files in a directory and return a list of them with their full path.

get_vpn_pids()

Extract all openvpn process ids on the machine.

kill_all_connections(pwd)

Kill all openvpn connections on the machine

Module Contents

sirup.utils.get_ip(echo=False, config_file=None)[source]

Query the current IP address of the computer.

The function calls https://ifconfig.me and retrieves the IP address.

Parameters:
  • echo (bool, optional) – If True, logging prints the retrieved IP address

  • config_file (str, optional) – Name of the vpn configuration file currently in use. If supplied, logging prints the name of the config file if the IP address cannot be retrieved

sirup.utils.lookup_strings_in_list(strings_to_check, list_of_strings)[source]

Scan a list of strings for presence of one or multiple strings in the same element.

Parameters:
  • strings_to_check (list) – the strings to look for.

  • list_of_strings (list) – the strings to scan.

Returns:

True if there is at least one element in list_of_strings that contains all strings in strings_to_check.

Return type:

bool

Example

>>> from sirup.utils import lookup_strings_in_list
>>> lookup_strings_in_list(["hello", "world"], ["hello, wonderful world", "hello universe"])
True
sirup.utils.check_connection(log_file, timeout, pwd, waiting_time=2)[source]

Wait and test for established connection until timeout.

The function repeatedly scans the log file of the openvpn process and looks for a string that indicates that the vpn connection was established. It exits when the string is found or timeout is reached.

Parameters:
  • log_file (str) – path to the log file of the vpn process.

  • timeout (int) – maximum time to wait for a successful conection.

  • pwd (str) – user root password.

  • waiting_time (int, optional) – Number of seconds to wait between consecutive scans.

Returns:

indicates whether connection is established.

Return type:

bool

sirup.utils.sudo_read_file(file, pwd=None)[source]

Read a file with root permission to a list.

Parameters:
  • file (str or TemporaryFileWithRootPermission) – the file to read

  • pwd (str, optional) – root password for the file. If file is a TemporaryFileWithRootPermission and no password is provided, the password is taken from the TemporaryFileWithRootPermission object.

Returns:

Content of the file, each line is one element in the list.

Return type:

list

sirup.utils.check_password(pwd)[source]

Run simple command to see if password is correct

sirup.utils.list_files_with_full_path(directory, rule=None)[source]

Collect all files in a directory and return a list of them with their full path.

Parameters:
  • directory (str) – directory path

  • rule (lambda, optional) – a lambda function that returns a bool. If supplied, list_files_with_full_path filters the files in the directory by whether rule returns True.

Returns:

files, possibly filtered, with the full path.

Return type:

list

class sirup.utils.RotationList(*args)[source]

Bases: list

Custom list for IP rotation.

__repr__()[source]

Return repr(self).

pop_append()[source]

Pop first element and append it at the end.

shuffle(randomizer)[source]

Randomly shuffle the list of proxies. This changes the order by which we iterate through them.

Parameters:

randomizer (random.Random) – pseudo-random number generator.

sirup.utils.get_vpn_pids()[source]

Extract all openvpn process ids on the machine.

Returns:

all openvpn process IDs.

Return type:

list

sirup.utils.kill_all_connections(pwd)[source]

Kill all openvpn connections on the machine

Parameters:

pwd (str) – root password to the machine.