Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- #ex) $ ix_uptime.py 192.168.0.1 username password
- import getpass
- from telnetlib import Telnet
- from sys import argv
- header = "IX2015# "
- command = "show uptime\r"
- #HOST = input("Enter your IX\'s IP addr: ")
- #user = input("Enter your remote account: ").encode('ascii')
- #password = getpass.getpass().encode("ascii")
- HOST = argv[1]
- user = argv[2].encode('ascii')
- password = argv[3].encode('ascii')
- tn = Telnet()
- #block any option
- tn.set_option_negotiation_callback(lambda x,y,z:None)
- tn.open(HOST)
- #login and cut welcome messages
- tn.read_until(b"login: ")
- tn.write(user + b"\r")
- if password:
- tn.read_until(b"Password: ")
- tn.write(password + b"\r")
- tn.read_until(header.encode("ascii"))
- tn.write("\r")
- tn.write(command.encode("ascii"))
- tn.write(b"exit\r")
- raw_msg = tn.read_all().decode('ascii')
- #delete header
- def check_header(txt):
- if txt.find(header) == -1:
- return txt.replace("\r", "\n")
- else:
- return ''
- clear_msg = ''.join(list(map(check_header, raw_msg.split('\n'))))
- print(clear_msg)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement