Solved

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

Posted on 2004-04-12
4
204 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
  • 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…

895 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now