Skip to content

Instantly share code, notes, and snippets.

@lttlrck
Created January 9, 2018 20:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lttlrck/b3d06811fb41286f08094f0396987905 to your computer and use it in GitHub Desktop.
Save lttlrck/b3d06811fb41286f08094f0396987905 to your computer and use it in GitHub Desktop.
get static DNS from Mikrotik router and output in .ssh/config format with comment as username
#!/usr/bin/python3
from tikapy import TikapyClient
from pprint import pprint
client = TikapyClient('192.168.74.1', 8728)
client.login('admin', 'banzai74')
res= client.talk(['/ip/dns/static/print'])
for key, value in res.items():
if 'comment' in value:
# print("Host", value['name'], value['address'], value['comment'])
print("Host", value['name'])
print(" HostName", value['address'])
print(" User", value['comment'])
else:
# print(value['name'], value['address'])
print("Host", value['name'])
print(" HostName", value['address'])
@lttlrck
Copy link
Author

lttlrck commented Jan 9, 2018

then use this alias to build .ssh/config for fast SSH selection to different hosts. Uses peco. Merges other hosts from ~/.ssh/config_

alias sss='ssh $(~/getStaticDns.py > ~/.ssh/config ; cat ~/.ssh/config_ >> ~/.ssh/config ; chmod 600 ~/.ssh/config; (grep Host ~/.ssh/config | grep -v HostName | cut -d" " -f2 | sort) | sort | uniq | peco --prompt=:)'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment