vpn dialing under windows:
import them from time import sleep class VPNHelper(object): def __init__(self, _vpnIP, _userName, _passWord, WinDir=r"C:\Windows\System32", RasDialFileName=r'\rasdial.exe'): self.IPToPing = _vpnIP self._VPNName = _vpnIP; self._UserName = _userName; self._PassWord = _passWord; self._WinDir = WinDir self._RasDialFileName = RasDialFileName self._VPNPROCESS = self._WinDir + self._RasDialFileName def TryConnectVPN(self): try: command = self._VPNName + " " + self._UserName + " " + self._PassWord os.system(self._VPNPROCESS + " " + command) return 1 except: print("----VPN connection failed!---") return 0 def TryDisConnectVPN(self): try: command = self._VPNName + " /d" os.system(self._VPNPROCESS + " " + command) except: print("---VPN disconnection failed!---") def Restart(self, waitingTime=0): import time self.TryDisConnectVPN() time.sleep(waitingTime) status=self.TryConnectVPN() while(status==0): status = self.TryConnectVPN() time.sleep(1.5) def changIP(): vpn = VPNHelper("Address", "Account", "Password") vpn.Restart(5) sleep(6)
pptp dialing under Linux (install pptp first):
def changIP(): o = 'F' while o =='F': try: print("Close the dialer!") #subprocess.getoutput('sudo pptpsetup --delete laoying') #sleep(0.5) pkill=subprocess.getoutput('sudo pkill -9 pptp') sleep(1) print('---1---',pkill) setuped=subprocess.getoutput('sudo pptpsetup --create laoying --server address --username account --password password --start') sleep(3) print ('---- 2 ----', setuped) pon=subprocess.getoutput('sudo pon laoying') print('---3---',pon) sleep(2) newvpn = subprocess.getoutput('sudo route add default dev ppp0') print('----4--',newvpn) sleep(6) if pon != '' or newvpn!='': o = 'F' continue print("Dial success!") return except: o = 'F' print('Dial error!') sleep(0.5) #if __name__=='__main__': # changIP()