Function: Host Grep
The Function
This is a function to check what we have set-up as a hostname for the times that I forget an IP address for a device on the LAN. It checks the hosts file and the ssh-config. The hosts
file has the IP address, but sometimes I can't remember the host-name, just the user-name, in which case checking the SSH config file can sometimes be helpful.
function hostgrep --argument-names HOST --description "Look for a hostname."
The Parts
Check Hosts
First check the /etc/hosts
file.
grep $HOST /etc/hosts
Check SSH
Now Check the ssh configuration.
grep --after-context 3 $HOST $HOME/.ssh/config