1、导入相关包
import time, os
from datetime import datetime
2、函数版
# 连接ADSL
def connect_ADSL(name,username,password):
cmd_string = f'rasdial {name} {username} {password}'
os.system(cmd_string)
time.sleep(5)
# 断开ADSL
def disconnect_ADSL(name):
cmd_string = f'rasdial {name} /disconnect'
os.system(cmd_string)
time.sleep(5)
# 重连ADSL
def reconnect_ADSL(name,username,password):
disconnect_ADSL(name)
connect_ADSL(name, username, password)
3、ADSL类
class ADSL(object):
def __init__(self):
self.name = ''
self.username = ''
self.password = ''
def set_adsl(self, account):
self.name = account["name"]
self.username = account["username"]
self.password = account["password"]
def connect(self):
cmd_str = f"rasdial {self.name} {self.username} {self.password}"
os.system(cmd_str)
time.sleep(5)
def disconnect(self):
cmd_str = f"rasdial {self.name} /disconnect"
os.system(cmd_str)
time.sleep(5)
def reconnect(self):
self.disconnect()
self.connect()