Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import telnetlib
- import time
- import getpass
- import sys
- import threading
- old_stdout = sys.stdout
- new_stdout = open('Processes_CPU.txt', '+a')
- COMMAND = b'sh processes cpu sorted 5sec'
- USER = input('Username: ').encode('utf-8')
- PASSWORD = getpass.getpass().encode('utf-8')
- IP = '192.168.1.100'
- print('Connection to device {}'.format(IP))
- t = telnetlib.Telnet(IP)
- t.read_until(b'Username:')
- t.write(USER + b'\n')
- t.read_until(b'Password:')
- t.write(PASSWORD + b'\n')
- t.write(b'terminal length 8\n')
- def Quiz():
- sys.stdout = new_stdout
- t.write(b'\n' + COMMAND + b'\n')
- output = t.read_very_eager().decode('utf-8')
- print(output)
- sys.stdout = old_stdout
- print('...')
- def someHandler():
- exit_flag = threading.Event()
- while not exit_flag.wait(timeout=4):
- Quiz()
- someHandler()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement