forked from MrTpat/newegg-bot-public
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVPN_refresher.py
53 lines (48 loc) · 1.56 KB
/
VPN_refresher.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import time
import os
import requests
import colors
import glob
import configparser
def killVPN() -> None:
os.system('killall openvpn &> /dev/null')
def getCurrIp() -> str:
r = requests.get('https://api.ipify.org?format=json')
if r.status_code != 200:
colors.printFail('Failed to detect IP address, retrying...')
time.sleep(1)
return getCurrIp()
else:
colors.printInfo('detected IP: ' + r.json()['ip'])
return r.text
def switchVPN(vpn_id: str, username: str, password: str) -> None:
formerIP = getCurrIp()
colors.printInfo('Swapping IP address...')
killVPN()
newConfigFile = getConfigFileName(vpn_id)
res = os.system('./vpnConnector.sh ' + newConfigFile + ' ' + username + ' ' + password)
if res != 0:
colors.printFail('Failed to connect to VPN. Trying again...')
switchVPN(vpn_id, username, password)
else:
time.sleep(10)
if formerIP == getCurrIp():
colors.printFail('Unsuccessful swap...trying again in 5 seconds')
time.sleep(5)
switchVPN(vpn_id, username, password)
else:
colors.printSuccess('Successful swap of IP address...')
def getConfigFileName(x: int) -> str:
return glob.glob("/etc/openvpn/configurations/*")[x]
vpn_id = 0
vpn_max = 150
config = configparser.ConfigParser()
config.read('vpnConfig.ini')
username = config['DEFAULT']['username']
password = config['DEFAULT']['password']
while True:
if vpn_id > vpn_max:
vpn_id = 0
switchVPN(vpn_id, username, password)
vpn_id = vpn_id + 1
time.sleep(600)