Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

How to get client machine IP address

by Jeganath KS (Novice)
on Aug 24, 2010 at 10:14 UTC ( #856897=perlquestion: print w/replies, xml ) Need Help??
Jeganath KS has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks, I need to develop a Perl script which should run on server machine to find out the requested client's IP address and the type of request(Actually I need to track what are all the web pages that are being requested by particular client machine). Is it possible with Perl? If yes, how do I get started?

Replies are listed 'Best First'.
Re: How to get client machine IP address
by JavaFan (Canon) on Aug 24, 2010 at 10:27 UTC
    The simplest way would be to just run an analyzer on the web server logs. There are many (free) analyzers out there. Just do a search.

    Bear in mind though that all you'll be getting is whatever IP address the last proxy in the request chain was using at the time. IP addresses do not identify machines. IP addresses are assigned to interfaces. One machine may have multiple interfaces (even the simplest setup will typically have at least two interfaces: for the loopback interface is also an IP address). One interface may have multiple IP addresses. And IP addresses may move.

      I have 20 machines connected through LAN with a single gateway. I need to track/log those 20 machines activity from the gateway machine(I just need to log what are all the websites requested, and from which machine that website was requested). Can I do it with Perl script. If yes, can you please guide me.

Re: How to get client machine IP address
by doug (Pilgrim) on Aug 24, 2010 at 17:01 UTC

    What is the server serving? Someone else assumed it was a web server, but I don't see that in your request. This does matter. If you can hack up the source for the server, then the easiest command is  getpeername() . If not, you'll have to go through some secondary thing like scanning log files or running  netstat .

    - doug

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://856897]
Approved by moritz
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2018-06-23 05:12 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (125 votes). Check out past polls.