Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 27th, 2000, 03:28 AM
coutts00 coutts00 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2000
Posts: 5 coutts00 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to coutts00
How do I display the IP address of a visitor to my web-site using Perl CGI scripts?

--
Steven Coutts
work@stevencoutts.org.uk

Reply With Quote
  #2  
Old September 27th, 2000, 04:08 AM
MeijdenB MeijdenB is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2000
Location: Alkmaar, The Netherlands
Posts: 123 MeijdenB User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 14
use $ENV{REMOTE_HOST} OR $ENV{REMOTE_ADDR} and check http://www.devshed.com/Talk/Forums/...TML/000177.html



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

------------------
E-mail me at: b.vandermeijden@pecoma.nl

Reply With Quote
  #3  
Old September 27th, 2000, 04:27 AM
coutts00 coutts00 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2000
Posts: 5 coutts00 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to coutts00
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.


Reply With Quote
  #4  
Old September 27th, 2000, 07:07 AM
freebsd
Guest
Dev Shed Newbie (0 - 499 posts)
 
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>

Reply With Quote
  #5  
Old September 27th, 2000, 07:40 AM
coutts00 coutts00 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2000
Posts: 5 coutts00 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to coutts00
Cheers exactly what I needed.

Reply With Quote
  #6  
Old September 27th, 2000, 08:04 AM
coutts00 coutts00 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2000
Posts: 5 coutts00 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to coutts00
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?

Reply With Quote
  #7  
Old September 27th, 2000, 09:10 AM
JSchoof JSchoof is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2000
Posts: 82 JSchoof User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
  #8  
Old September 27th, 2000, 12:04 PM
tron's Avatar
tron tron is offline
SwollenMember
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Location: the master control
Posts: 264 tron User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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).]

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > Remote IP Address

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap