#!/usr/bin/env python3 """Read-only inspection of the RB3011 lab router. Does not touch RB4011.""" from __future__ import annotations import time import paramiko MK = ("192.168.88.249", "admin", "1234") def wait_prompt(shell, timeout=18) -> str: buf = b"" end = time.time() + timeout while time.time() < end: time.sleep(0.12) if shell.recv_ready(): buf += shell.recv(65535) end = time.time() + 1.5 if b"> " in buf[-200:]: break return buf.decode("utf-8", "replace") def cmd(shell, line: str, timeout=18) -> str: shell.send(line + "\r") out = wait_prompt(shell, timeout) print("\n===== " + line + " =====") print(out[-3500:]) return out def main() -> None: mk = paramiko.SSHClient() mk.set_missing_host_key_policy(paramiko.AutoAddPolicy()) mk.connect( MK[0], username=MK[1], password=MK[2], timeout=20, allow_agent=False, look_for_keys=False, ) shell = mk.invoke_shell(width=200, height=60) wait_prompt(shell, 12) cmd(shell, "/system identity print") cmd(shell, "/system resource print") cmd(shell, "/system package print where name~\"wireguard\"") cmd(shell, "/interface wireguard print") cmd(shell, "/interface wireguard peers print") cmd(shell, "/ip address print") cmd(shell, "/ip dns print") cmd(shell, ":put [:resolve wifi.otantik.cm]") cmd(shell, ":put [:resolve 83.147.38.107]") mk.close() if __name__ == "__main__": main()