The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Perl Programming
|
Remote IP Address
Discuss Remote IP Address in the Perl Programming forum on Dev Shed. Remote IP Address Perl Programming forum discussing coding in Perl, utilizing Perl modules, and other Perl-related topics. Perl, the Practical Extraction and Reporting Language, is the choice for many for parsing textual information.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

September 27th, 2000, 03:28 AM
|
|
Junior Member
|
|
Join Date: Sep 2000
Posts: 5
Time spent in forums: < 1 sec
Reputation 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
|

September 27th, 2000, 04:08 AM
|
|
Contributing User
|
|
Join Date: May 2000
Location: Alkmaar, The Netherlands
Posts: 123
Time spent in forums: < 1 sec
Reputation Power: 14
|
|
|

September 27th, 2000, 04:27 AM
|
|
Junior Member
|
|
Join Date: Sep 2000
Posts: 5
Time spent in forums: < 1 sec
Reputation 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.
|

September 27th, 2000, 07:07 AM
|
|
Guest
|
|
Posts: n/a
Time spent in forums:
Reputation Power:
|
|
|
##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>
|

September 27th, 2000, 07:40 AM
|
|
Junior Member
|
|
Join Date: Sep 2000
Posts: 5
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
Cheers exactly what I needed.
|

September 27th, 2000, 08:04 AM
|
|
Junior Member
|
|
Join Date: Sep 2000
Posts: 5
Time spent in forums: < 1 sec
Reputation 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?
|

September 27th, 2000, 09:10 AM
|
|
Contributing User
|
|
Join Date: Aug 2000
Posts: 82
Time spent in forums: 1 h 23 m 46 sec
Reputation Power: 13
|
|
|
Backslash the quotes:
print "<input type="hidden" name="ip" value="$ip">n"
Have fun.
|

September 27th, 2000, 12:04 PM
|
 |
SwollenMember
|
|
Join Date: Jun 2000
Location: the master control
Posts: 264
Time spent in forums: 13 h 14 m 57 sec
Reputation Power: 13
|
|
|
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).]
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|