Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- b-davis login:
- Password:
- Last login: Mon Aug 29 20:28:24 EDT 2016 from localhost on pts/5
- import telnetlib
- import re
- pw = "p@ssw0rd"
- user = "bdavis"
- regex = [
- b"[Ll]ogin.", # b"[Ll]ogin" works here
- b"[Pp]assword",
- b'>',
- b'#']
- tn = telnetlib.Telnet("1.2.3.4")
- while type(tn.get_socket()) is not int:
- result = tn.expect(regex, 5) # Retrieve send information
- s = result[2].decode()
- if re.search("[Ll]ogin$",s) is not None:
- print("Do login stuff")
- print(result)
- tn.write((user + "n").encode()) # Send Username
- elif re.search("[Pp]assword",s) is not None:
- print("Do password stuff")
- tn.write((pw + "n").encode()) # Send Password
- elif re.search('>',s) is not None:
- print("Do Cisco User Stuff")
- tn.write(b"exitn") # exit telnet
- tn.close()
- elif re.search('#',s) is not None:
- print("Do Cisco Admin Stuff")
- else:
- print("I Don't understand this, help me:")
- print(s)
- tn.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement