Last active
September 3, 2020 14:08
-
-
Save gerardo-junior/00a670bb060ab2aa5b6c6a78916bd66e to your computer and use it in GitHub Desktop.
Add suport DNS srv record type to ssh client (https://www.ietf.org/rfc/rfc2782.txt)
This file contains hidden or 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
#!/bin/bash | |
target_host=$1 | |
if [ ! -z "$2" ];then | |
target_port=$2 | |
else | |
target_port="22" | |
fi | |
while read record;do | |
if [ ! -z "$record" ];then | |
host=$(echo $record | awk '{print $NF}') | |
port=$(echo $record | awk '{print $(NF-1)}') | |
if timeout 1 bash -c "cat < /dev/null > /dev/tcp/$host/$port" &> /dev/null;then | |
target_host=$host | |
target_port=$port | |
break | |
fi | |
fi | |
done < <(dig +short SRV _ssh._tcp.$target_host @$(dig +short NS $(echo $target_host | awk -F '.' '{print $(NF-1)"."$NF}') | head -n1) | sort -nk1) | |
socat STDIO TCP:$target_host:$target_port 2> /dev/null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
just add -o ProxyCommand=sshsrv-proxy-command.sh %h %p on ssh command
or edit ~/.ssh/config file and put:
Host *.DOMAIN
ProxyCommand=sshsrv-proxy-command.sh %h %p