Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

code ttyp3 Nov 8 13:09 (dsl092-212-009.atl1.dsl.speakeas) strike ttyp5 Nov 8 00:24 (1cust62.tnt4.hamilton.on.da.uu.n)
Is there a way to get the a users full ip address when it's cut off like the above?


-finger is disabled.

Replies are listed 'Best First'.
Re: getting unix users ip addresses
by kjherron (Pilgrim) on Nov 09, 2001 at 02:20 UTC
    It's going to depend on the system that you're using. The information printed by the commands "last", "w", and "who" comes from the system's wtmp and utmp files. The specific format of these files will vary widely from one system to another, and this determines exactly what information is printed by last, who, etc.

    On the systems I'm familiar with (solaris, for example), wtmp records contain the hostname but not the IP address; on solaris the hostname field is 257 characters wide, but on others it may be much smaller, causing the hostnames to be truncated as in your example.

    On other systems it's certainly possible that these records contain IP addresses, in which case there's probably some "last" option to print IP addresses instead of hostnames.

Re: getting unix users ip addresses
by Erik Hensema (Sexton) on Nov 09, 2001 at 01:25 UTC

    Sure, no problem. Try something like this:

    use Socket; # open and read who here $addr = inet_aton($1) if m/\((.*)\)/;
Re: getting unix users ip addresses
by clintp (Curate) on Nov 09, 2001 at 01:25 UTC
    Miss Cleo might be able to help you, but otherwise you're outta luck.

    Where'd ya get the data from? who? last? Maybe you should parse up the wtmp file yourself with a module, if that's what's needed.

Re: getting unix users ip addresses
by blakem (Monsignor) on Nov 09, 2001 at 01:38 UTC
    try using the -i option to last.....
    % last -i

    -Blake