sirup.IPRotator

Rotate IP address with OpenVPN

Classes

IPRotator

Class to manage a set of VPN configuration files and rotate the IP by iterating across the configuration files.

Module Contents

class sirup.IPRotator.IPRotator(auth_file, config_location, pwd=None, seed=None, config_file_rule=None, track_ip=True)[source]

Class to manage a set of VPN configuration files and rotate the IP by iterating across the configuration files.

Note

When the class is instantiated, any existing openvpn processes are killed. This is for reasons of safety, simplicity and making sure that the VPN connector works as intended.

Parameters:
  • auth_file (str) – Path to the file containing authentication credentials for VPN connections.

  • config_location (str) – Path to the directory where VPN configuration files are stored.

  • pwd (str, optional) – Sudo password. If not provided, the user is asked to provide it at class instantiation.

  • seed (int, optional) – Seed for the random number generator to shuffle config files.

  • config_file_rule (str, optional) – Rule to filter config files in the config_location.

  • track_ip (bool, optional) – If True, the IP address is queried after each connect and disconnect. For long-running programs, it is better to set track_ip=False in order to respect the query limits of the IP address API.

config_queue

List of OpenVPN configuration files.

Type:

sirup.utils.RotationList

auth_file

OpenVPN authentication file with the user credentials.

Type:

str

randomizer

Pseudo-random number generator to shuffle the config_queue.

Type:

random.Random

track_ip

Indicates whether the IP address should be tracked between connections, disconnections and rotations. If True, queries https://ifconfig.me for the IP address after each change of the IP address, which is not recommended for long-running programs.

Type:

bool

pwd

User root password to access the OpenVPN command-line interface.

Type:

str

connector

If a VPN tunnel is active, the sirup.VPNConnector object that is responsible for the connection.

Type:

None or sirup.VPNConnector.VPNConnector

__repr__()[source]

Return repr(self).

_make_repr_inputs()[source]
connect(shuffle=False, max_trials=2000)[source]

Connect to the server associated with the first configuration file in self.config_queue.

Parameters:
  • shuffle (bool, optional) – If True, shuffle the config files before connecting.

  • max_trials (int, optional) – Maximum number of connection attempts before raising an exception.

disconnect()[source]

Disconnect from the current server.

rotate()[source]

Rotate to the next server.