Solved

Your IP address is: xxx.xxx.xxx.xxx

Posted on 2004-04-12
4
209 Views
Last Modified: 2013-12-25
When a user accesses the web page, how do I display the IP address they are coming from.  I'd like to do this with the CGI.pm PERL module. (and store it in a variable)

TIA
0
Comment
Question by:ramble
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 

Accepted Solution

by:
mannie earned 50 total points
ID: 10805784
Hi

Like this:

$query=new CGI();
print $query->remote_host(); #returns host or IP if host unavail
OR
print $query->http('REMOTE_ADDR') #for IP directly

all http enviroment variables is listed here
http://hoohoo.ncsa.uiuc.edu/cgi/env.html

Best regards
Linus
0
 

Author Comment

by:ramble
ID: 10806547

Thanks, Points awarded.  However, if it's quick...what if you'd want to get the hostname...example, if the IP address resoved to: some.domains.com.  And you wanted that stored in the variable instead of the IP.

Thanks_ramble
0
 

Expert Comment

by:mannie
ID: 10808875
use the print $query->http($string) where $string is any of the http enviroment variables listet on the page in the previous comment. So replace the REMOTE_ADDR with REMOTE_HOST and you'll get the hostname, if that is what you ment with your question?

/Linus
0
 

Author Comment

by:ramble
ID: 10823803

I never tried the ->ADDR string, so, interesting enough, I'm still only receiving the numerical IP address.  (with the remote_host).  But, perhaps it's just not resolving correctly with my "test machine".  Thanks
0

Featured Post

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently I have been answering a lot of questions like this in IT forums that I frequent. The question posed is usually something along the lines of "We have software X installed and need to uninstall it for reason Y" or some other variant of the sa…
This article will show, step by step, how to integrate R code into a R Sweave document
The viewer will learn how to dynamically set the form action using jQuery.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question