Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Problems with simple script

wizardmaxwizardmax Member Posts: 2
I am trying to write a script that shows the IP of incoming request. The code works, but gives me a wrong IP which it gets from I dont know were. I am running this code on tripod. Any idea why this shouldnt work?

#!/usr/local/bin/perl

my @ip = ($ENV{REMOTE_ADDR});

print

Your IP is @ip



END

Comments

  • heeroyuyheeroyuy Member Posts: 125
    Try setting it to $ip=$ENV{REMOTE_ADDR}. Its returning a string, and your trying to set an entire array equal to that string :) That works fine for me, I use it to log user access to my website. The following is the source:

    [code]
    sub access_log() {
    open("ACCESS_LOG",">>../logs/.access_log");
    $date = `date`;
    print ACCESS_LOG "Date: $date
    User: ";
    print ACCESS_LOG $ENV{'REMOTE_USER'};
    print ACCESS_LOG "
    User IP: ";
    $address=$ENV{'REMOTE_ADDR'};
    print ACCESS_LOG "$address";
    print ACCESS_LOG "
    Script Location: ";
    print ACCESS_LOG $ENV{'SCRIPT_NAME'};
    print ACCESS_LOG "
    --------------------------------------
    ";
    close(ACCESS_LOG);
    }
    [/code]

    Hope that helps :)
    -----------------------
    "The three principle virtues of a programmer are laziness, impatience, and hubris"

  • wizardmaxwizardmax Member Posts: 2
    I tryed that, and still have the same problem.

    : Try setting it to $ip=$ENV{REMOTE_ADDR}. Its returning a string, and your trying to set an entire array equal to that string :) That works fine for me, I use it to log user access to my website. The following is the source:
    :
    : [code]
    : sub access_log() {
    : open("ACCESS_LOG",">>../logs/.access_log");
    : $date = `date`;
    : print ACCESS_LOG "Date: $date
    User: ";
    : print ACCESS_LOG $ENV{'REMOTE_USER'};
    : print ACCESS_LOG "
    User IP: ";
    : $address=$ENV{'REMOTE_ADDR'};
    : print ACCESS_LOG "$address";
    : print ACCESS_LOG "
    Script Location: ";
    : print ACCESS_LOG $ENV{'SCRIPT_NAME'};
    : print ACCESS_LOG "
    --------------------------------------
    ";
    : close(ACCESS_LOG);
    : }
    : [/code]
    :
    : Hope that helps :)
    : -----------------------
    : "The three principle virtues of a programmer are laziness, impatience, and hubris"
    :
    :

  • XfactorXfactor Member Posts: 343
    : I am trying to write a script that shows the IP of incoming request. The code works, but gives me a wrong IP which it gets from I dont know were. I am running this code on tripod. Any idea why this shouldnt work?
    :
    : #!/usr/local/bin/perl
    :
    : my @ip = ($ENV{REMOTE_ADDR});
    :
    : print <<END;
    :
    : Content-Type: text/html


    :
    :
    : <html>
    :
    : Your IP is @ip
    :
    :
    :
    : END

    Try taking out all the HTML tags first. See if you can get the right IP by just running the script from the command line. Once it works on command line, then add your HTML and everything should be fine.
    The only thing I see is place a print in front of "Your IP is $ip";
    X
  • brtkltbrtklt Member Posts: 237
    You don't have quotes around REMOTE_ADDR in ($ENV{'REMOTE_ADDR'});
    Don't know if that'll fix it but it was something I noticed.

    : I am trying to write a script that shows the IP of incoming request. The code works, but gives me a wrong IP which it gets from I don’t know were. I am running this code on tripod. Any idea why this shouldn’t work?
    :
    : #!/usr/local/bin/perl
    :
    : my @ip = ($ENV{REMOTE_ADDR});
    :
    : print <<END;
    :
    : Content-Type: text/html


    :
    :
    : <html>
    :
    : Your IP is @ip
    :
    :
    :
    : END
    :

  • Andre YoungAndre Young USAMember Posts: 0

    _ { http://forcoder.org } free ebooks and video tutorials about // Ruby, C#, PL/SQL, MATLAB, C++, C, Perl, Delphi, Go, Objective-C, PHP, Python, Visual Basic, Assembly, JavaScript, R, Swift, Scratch, Visual Basic .NET, Java Fortran, Clojure, Dart, Logo, Kotlin, Ada, Transact-SQL, Rust, Bash, Crystal, Erlang, Scheme, ML, Hack, FoxPro, Awk, Apex, F#, Julia, VBScript, COBOL, Lua, ABAP, D, Prolog, Lisp, Scala, SAS, LabVIEW, Alice // ____

Sign In or Register to comment.