Use get_remote_ip to find the address of an ssh client.
Use get_remote_ip -n to report the remote hostname if
available.
--- /dev/null
+#!/usr/bin/perl
+#
+# get_remote_ip: Get IP address (or hostname) of the host from which this SSH
+# session is active.
+# Usage: get_remote_ip [-n]
+#
+
+use Socket;
+
+my $ip = $ENV{SSH_CLIENT};
+exit 111 unless $ip;
+
+$ip =~ s/\s.*//; $ip =~ s/^::ffff://;
+unless ($ARGV[0] eq "-n") {
+ print "$ip\n";
+ exit 0;
+}
+
+my $name = gethostbyaddr(inet_aton($ip), AF_INET);
+if ($name) { $name =~ s/\..*//; print "$name\n"; } else { print "$ip\n" }
+exit 0;