#!/usr/local/bin/perl -s
################################################################################
# pip v1.3p 		Nov 15, 1996 Dale Bewley <dale@bewley.net>
# pip v1.2s 		Aug 03, 1995 Dale Bewley <dbewley@iupui.edu>
#------------------------------------------------------------------------------#
# This script and others found at http://www.bewley.net/perl/
#
# This program will require modification if used outside of IUPUI. Or off HP-UX.
# This script allows you to get the ip number of the machine a user is logged
# in from. Useful to get the IP of a PPP user if logged into the local mahine,
# which is what I wrote this for. 
# Returns nothing if user is not on the local machine via PPP or if they
# are telneted from somewhere else. Unless you add -v.
#
# Why would you want this information? If you are running a web server on a
# dialup then you need to update the link to your new IP each time you dialin.
# See hserv at the URL above for the rest of the story.
#
#	- A little info about how the IUPUI PPP IPs were alotted. -
#  If you finger @134.68.249.* you get:
# 	   [134.68.249.1]=X2S2 [134.68.249.2]=X2S3 
# 	   [134.68.249.3]=X2S4 [134.68.249.4]=X2S5
#
# Before you do a `host` on the hostname shown, i.e. x2s3p4.dialin.iupui.edu,
# you must add 1 to the server number for .1 .2 .3, i.e. x2s3p1 becomes x2s4p1,
# but for .4 just add 20 to the IP you find with the host name shown, because
# there is no x2s5.
#  But if you do a `who` the server number will be adjusted, and the actual
# hostname (or if on .4 IP number) will be shown.
# 	*note you can no longer finger .249 unless on .249. 
#
# All of the above is more or less a moot point since the new 28.8 dialins 
# are on 134.68.239 and 243 without hostnames.
#
# Interesting related file is: http://www.bewley.net/perl/examples/subnets.txt
################################################################################

if (! $ARGV[0]) {
        print "Usage: $0 [-v] <username>\n";
        exit;
}
 
# who the specified user
@who = `who -R | grep $ARGV[0]`;
 
foreach (@who) {
        $_ =~ s/.*\((.*)\)/$1/; # grab after first ( up to following )
        push (@hosts, $_);
        # at this point @hosts is a list of hosts the user is on
        # from. let's figure out which ones are PPP.
        if (/dialin/ || /^134.68.(249|248|239|240)/) {
                # i'm going to assume user is only logged in from 1 PPP
                $ppp_ip = $_;
        }
}
 
print "$ARGV[0] is on from hosts: ", join(", ", @hosts) if ($v);
print "$ARGV[0] is on from PPP: " if ($v);
print $ppp_ip;

