#!/usr/bin/env python3 from __future__ import annotations import paramiko import time from pathlib import Path JUMP = ("100.80.255.113", "otantik", "DeararbsFr2@") MK = ("172.30.0.1", "admin", "demopass") OUT = Path(r"c:\laragon\www\light-otantik-nux\scripts\_mk_vpn.txt") COMMANDS = [ "/ip address print detail without-paging", "/ip route print detail without-paging", "/interface print without-paging", "/interface wireguard export", "/interface wireguard peers export", "/interface ovpn-client export", "/interface sstp-client export", "/interface l2tp-client export", "/interface pptp-client export", "/interface eoip export", "/interface gre export", "/ppp profile export", "/ppp secret export", "/ip ipsec export", "/ip cloud export", "/ip hotspot ip-binding print without-paging", "/ip hotspot walled-garden ip print without-paging", ] def wait_prompt(shell, timeout=15) -> str: buf = b"" end = time.time() + timeout while time.time() < end: time.sleep(0.2) if shell.recv_ready(): buf += shell.recv(65535) end = time.time() + 2.0 if b"> " in buf[-120:]: break return buf.decode("utf-8", "replace") def main() -> None: jump = paramiko.SSHClient() jump.set_missing_host_key_policy(paramiko.AutoAddPolicy()) jump.connect(JUMP[0], username=JUMP[1], password=JUMP[2], timeout=20, allow_agent=False, look_for_keys=False) chan = jump.get_transport().open_channel("direct-tcpip", (MK[0], 22), ("127.0.0.1", 0)) mk = paramiko.SSHClient() mk.set_missing_host_key_policy(paramiko.AutoAddPolicy()) mk.connect(MK[0], username=MK[1], password=MK[2], sock=chan, timeout=20, allow_agent=False, look_for_keys=False) shell = mk.invoke_shell(width=240, height=80) wait_prompt(shell, 12) parts = [] for cmd in COMMANDS: shell.send(cmd + "\r") out = wait_prompt(shell, 18) parts.append("\n===== " + cmd + " =====\n" + out) print("got", cmd) OUT.write_text("\n".join(parts), encoding="utf-8", errors="replace") print("WROTE", OUT, "chars", OUT.stat().st_size) mk.close() jump.close() if __name__ == "__main__": main()