Created
January 9, 2018 20:08
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
then use this alias to build
.ssh/config
for fast SSH selection to different hosts. Usespeco
. 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=:)'