Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- import pexpect
- import getpass
- import telnetlib
- import socket
- ipfile = input("Enter site (IP address file): ")
- user = input("Enter username: ")
- password = getpass.getpass("Enter password")
- outputfile = ((ipfile)+".output")
- f = open(outputfile, 'w')
- f.write("")
- f.close()
- with open(ipfile) as ips:
- all_ips = [x.rstrip() for x in ips] # get all ips in a list and strip newline
- for ip in all_ips:
- tn = telnetlib.Telnet(ip,23,2)
- tn.read_until(b"Username: ")
- tn.write(user.encode('ascii') + b"n")
- if password:
- tn.read_until(b"Password: ")
- tn.write(password.encode('ascii') + b"n")
- tn.write(b"term len 0n")
- tn.write(b"sh invenn")
- tn.write(b"logoutn")
- # print(tn.read_all().decode('ascii'))
- with open(outputfile,"ab") as f: #write to a file
- f.write(tn.read_all())
- Traceback (most recent call last):
- File "./test4.py", line 22, in <module>
- tn = telnetlib.Telnet(ip, 23,2)
- File "/usr/lib/python3.5/telnetlib.py", line 218, in __init__
- self.open(host, port, timeout)
- File "/usr/lib/python3.5/telnetlib.py", line 234, in open
- self.sock = socket.create_connection((host, port), timeout)
- File "/usr/lib/python3.5/socket.py", line 711, in create_connection
- raise err
- File "/usr/lib/python3.5/socket.py", line 702, in create_connection
- sock.connect(sa)
- socket.timeout: timed out
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement