如何在超时时更改vpn ip - Vpn rotator script

时间:2017-07-27 11:57:28

标签: python security vpn

我想编写一个脚本,根据ping修改vpn ip。例如,当我连续ping" google.com"并且它接收超时它应该立即将vpn ip更改为另一个ip(openvpn)。必要的配置存储在一个文件夹中。 如何使当前脚本在超时时旋转vpns?

 import os
import numpy as np
hostname = "google.com" 
def reconnect_vpn():
    all_files = os.listdir(path)
    while True:
        entry_nr = np.randint(len(all_files))
        file = all_files[entry_nr]
        if file.split('.')[1] == 'ovpn':
            break
    os.system('openvpn '+file)


while True:
    response = os.system("ping -c 1" + hostname)

    #and then check the response...
    if response == 0:
      continue;
    else:
      reconnect_vpn()

0 个答案:

没有答案
相关问题