Import Sys
Import Telnetlib
Import time
HOST = ["172.18.217.12", "172.18.217.13"] #往后一直加即可
USER = "username"
PASSWORD = "PASSWORD"
Command1 = "NET user test 1/add" #添加用户
Command2 = "net localgroup Administrators Test/add" #给将用户添加到组
Wait_time = 1
For host in Host:
TN = Telnetlib. Telnet (host,timeout = 10)
#tn. Read_eager (). Decode (' Utf-8 ')
Tn.read_until (b ' Login: ')
Tn.write (User.encode (' utf-8 ') + "\ r". Encode (' Utf-8 '))
Time.sleep (Wait_time)
#tn. Read_very_eager (). Decode (' Utf-8 ')
Time.sleep (Wait_time)
#tn. Read_until (b ' Administrator\n\rpassword: ')
Tn.write (Password.encode (' utf-8 ') + "\ r". Encode (' Utf-8 '))
Time.sleep (Wait_time)
Tn.read_very_eager (). Decode (' Utf-8 ') #这句话的意思只是读取信息, but the withdrawal can not run successfully, do not know why, the front if not read_until, all with the method of sleep, then the note off Read_very _eager must be added to succeed.
Tn.write (Command1.encode (' utf-8 ') + "\ r". Encode (' Utf-8 '))
Time.sleep (Wait_time)
Tn.write (Command2.encode (' utf-8 ') + "\ r". Encode (' Utf-8 '))
Time.sleep (Wait_time)
A = Tn.read_very_eager ()
Tn.close ()
Print (Host + a.decode (' GBK '))
Print (' \ n ')
Solve the problem of building users, add groups, so some usage did not delve into, here the transcoding is very cumbersome, and, \ n failed to execute the success \ R can
py3.5 instances of Telnet (bulk user creation on remote machines)