X-Git-Url: http://git.iain.cx/?a=blobdiff_plain;f=opt%2Fbin%2Fget_remote_ip;fp=opt%2Fbin%2Fget_remote_ip;h=736a8c5e97d6e1e04887091f3a055a27b7961c9e;hb=0311d5d91bb476b3a60866579aaf2c8244797eb9;hp=0000000000000000000000000000000000000000;hpb=8a304871323fd8c0ab81b81a9082f07d03a1fa0c;p=profile.git diff --git a/opt/bin/get_remote_ip b/opt/bin/get_remote_ip new file mode 100755 index 0000000..736a8c5 --- /dev/null +++ b/opt/bin/get_remote_ip @@ -0,0 +1,21 @@ +#!/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;