Skip to content

Instantly share code, notes, and snippets.

@plattrap
Last active April 29, 2019 22:18
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 plattrap/e8d7f9b1ffe7c0ea27c7dd380341cf95 to your computer and use it in GitHub Desktop.
Save plattrap/e8d7f9b1ffe7c0ea27c7dd380341cf95 to your computer and use it in GitHub Desktop.
Lookup all the NETBIOS and AVAHI names on the local network. And scan for their ssh hostkeys.
#!/usr/bin/env bash
ADDRESSES=`sudo arp-scan --localnet --ignoredups --interface=enp0s25 | grep $'\t' | cut -f1`
#echo $ADDRESSES
get_ssh_info () {
local out err
{
out=( $(ssh-keyscan -t ed25519 $1 2>/dev/fd/3) )
err=( $(cat<&3) )
} 3<<EOF
EOF
if [[ -z ${out[2]} ]]; then
key=""
else
key=${out[2]}
fi
if [[ ${err[2]} == "Connection" ]]; then
host_type="refused"
else
host_type="${err[2]} ${err[3]}"
fi
#echo $type :: $key
}
for ADDRESS in $ADDRESSES
do
NAME=`wbinfo --WINS-by-ip=${ADDRESS} 2>/dev/null | cut -f2`
if [[ -z "$NAME" ]]; then
NAME="-"
fi
NAME1=`avahi-resolve-address ${ADDRESS} 2>/dev/null | cut -f2`
if [[ -z "$NAME1" ]]; then
NAME1="-"
fi
get_ssh_info $ADDRESS
printf "%-15s | %-15s | %-30s | %-8s | %s\n" $ADDRESS $NAME $NAME1 "${key:(-8)}" "$host_type"
done
echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment