Python自动登录脚本

import tkinter as tk
from tkinter import messagebox
import telnetlib
from selenium import webdriver


root = tk.Tk()  # 创建窗口
root.title('产测小工具')
root.geometry("300x100+630+80")  # 长x宽+x*y


#menubar = Menu(root)
#oot.config(menu=menubar)

#A = Menu(menubar,tearoff=0)
#menubar.add_cascade(label='11',menu=A)


btn1 = tk.Button(root)  # 创建按钮,并且将按钮放到窗口里面
btn1["text"] = "语音拨号"  # 给按钮一个名称
btn1.pack()  # 按钮布局

btn2 = tk.Button(root)
btn2["text"] = "打开页面"
btn2.pack()

btn3 = tk.Button(root) #执行gon的下发指令
btn3["text"] = "设置SN"
btn3.pack()


def SetSn(e):
    '''创建弹窗'''
    try:
        tn=telnetlib.Telnet('192.168.1.1',port=23,timeout=10)
    except Exception as e:
        print("--------connect is error ------")
    #print("1111111111")
    name = "tc login:"
    name = name.encode()
    telecomadmin = "telecomadmin"
    telecomadmin = telecomadmin.encode()

    password = "nE7jA%5m"
    password = password.encode()

    Set = "ifconfig ra0 down"
    #Set = "tcapi set gpon_onu SerialNumber PTIN65AB57FB"
    Set=Set.encode()

    Commit = "tcapi commit gpon"
    Commit = Commit.encode()

    Save = "tcapi save"
    Save = Save.encode()

    try:
        respon = tn.read_until(name)
    except Exception as e:
        print("------respon is error -------")
    print("the is :",respon)
    
    try:
        tn.write(telecomadmin+b'\n')
    except Exception as e:
        print("---------write error-----")
        
    #tn.read_until('Password:')
    tn.write(password+b'\n')
    print("111111111")
    tn.write(Set+b'\n')
    
    tn.write(Commit+b'\n')
    tn.write(Save+b'\n')


    messagebox.showinfo("窗口名称", "设置SN完成")
    
def test(e):
    '''创建弹窗'''
    try:
        tn=telnetlib.Telnet('192.168.1.1',port=23,timeout=10)
    except Exception as e:
        print("--------connect is error ------")
    #print("1111111111")
    name = "tc login:"
    name = name.encode()
    telecomadmin = "telecomadmin"
    telecomadmin = telecomadmin.encode()

    password = "nE7jA%5m"
    password = password.encode()

    evcom = "evcom"
    evcom=evcom.encode()

    di = "di"
    di = di.encode()

    ir = "ir if=0"
    ir=ir.encode()
    try:
        respon = tn.read_until(name)
    except Exception as e:
        print("------respon is error -------")
    print("the is :",respon)
    
    try:
        tn.write(telecomadmin+b'\n')
    except Exception as e:
        print("---------write error-----")
        
    #tn.read_until('Password:')
    tn.write(password+b'\n')
    print("111111111")
    tn.write(evcom+b'\n')
    tn.write(di+b'\n')
    tn.write(ir+b'\n')

    messagebox.showinfo("窗口名称", "点击成功")

def web(e):
    browser = webdriver.Chrome()
    data = {"username":"telecomadmin","password":"nE7jA%5m","Language_Flag":"0","selectLanguage":"Chinese"}
    browser.get("http://192.168.1.1")
    
    browser.implicitly_wait(10)
    browser.find_element_by_id('username').clear()    #清除输入框数据
    browser.find_element_by_id('username').send_keys('telecomadmin')    #输入账号
    browser.find_element_by_id('password').clear()    #
    browser.find_element_by_id('password').send_keys('nE7jA%5m')    #输入密码
    browser.find_element_by_id('loginbutton').click()


    messagebox.showinfo("窗口名称", "点击成功")


btn1.bind("", test)  # 将按钮和方法进行绑定,也就是创建了一个事件
btn2.bind("",web)
btn3.bind("",SetSn)



root.mainloop()  # 让窗口一直显示,循环

你可能感兴趣的:(python,python,开发语言)