Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

@lttlrck 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
You can’t perform that action at this time.