#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Posts
    5
    Rep Power
    0
    How do I display the IP address of a visitor to my web-site using Perl CGI scripts?

    --
    Steven Coutts
    work@stevencoutts.org.uk
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Location
    Alkmaar, The Netherlands
    Posts
    123
    Rep Power
    14
    use $ENV{REMOTE_HOST} OR $ENV{REMOTE_ADDR} and check http://www.devshed.com/Talk/Forums/F...ML/000177.html



    ------------------
    Good luck,
    Bas

    ------------------
    E-mail me at: b.vandermeijden@pecoma.nl
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Posts
    5
    Rep Power
    0
    Ok I use this code right -:

    $ip = $ENV{'REMOTE_ADDR'};
    $n = `nslookup $ip | grep Name`; chop($n);
    $host = substr($n, rindex($n, " ")+1);
    if ($host eq "") {
    $host=$ENV{'REMOTE_ADDR'};
    }

    I take it this will be in a file in the cgi-bin directory called say ip.cgi

    Now how do include this in my html file so it displays the IP? Obviously I need some kind of output statement in the script too.

  6. #4
  7. No Profile Picture
    freebsd
    Guest
    Devshed Newbie (0 - 499 posts)
    ##http://www.domain.com/cgi-bin/ip.cgi##
    #!/usr/local/bin/perl

    $ip = $ENV{'REMOTE_ADDR'};
    $n = `nslookup $ip | grep Name`; chop($n);
    $host = substr($n, rindex($n, " ")+1);
    if ($host eq "") {
    $host=$ENV{'REMOTE_ADDR'};
    }
    print "Content-type: text/htmlnn";
    print "Host: $host<br>n";
    print "IP: $ip<br>n";
    exit;

    ##http://www.domain.com/myfile.html##
    <html>
    <body>
    <!--#include virtual="/cgi-bin/ip.cgi" -->
    </body>
    </html>
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Posts
    5
    Rep Power
    0
    Cheers exactly what I needed.
  10. #6
  11. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Posts
    5
    Rep Power
    0
    I'm now trying to store these in hidden values on the page using the following appended to the end of the script.

    print "<input type="hidden" name="ip" value="$ip">n"

    Now I realise the problem I am having stems from the quotes used in the print statement, how is it I overcome this?
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Posts
    82
    Rep Power
    14

    Backslash the quotes:


    print "<input type="hidden" name="ip" value="$ip">n"

    Have fun.
  14. #8
  15. SwollenMember
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Location
    the master control
    Posts
    264
    Rep Power
    14
    freebsd knows his stuff, so use that example, or you could do it using CGI:

    #!/usr/local/bin/perl

    use CGI;

    my $query = new CGI;

    print $query->header;
    print $query->remote_host;

    exit;

    [This message has been edited by tron (edited September 27, 2000).]

IMN logo majestic logo threadwatch logo seochat tools logo