SSH sets the environment variable SSH_CONNECTION to contain client IP address, client port number, server IP address, and server port number seperated by spaces.
You can use
echo ${SSH_CONNECTION%% *}
to get the client's IP address. To get the DNS name use something like host or dig -x:
host ${SSH_CONNECTION%% *}
dig -x ${SSH_CONNECTION%% *}
Sample Screenshot:
Thank you for your support!
Keep Learning!
Keep going!