minixman has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.
  • Comment on Getting client ip address from socket connect

Replies are listed 'Best First'.
Re: Getting client ip address from socket connect
by marto (Cardinal) on Nov 01, 2005 at 12:30 UTC
    Hi minixman,

    "All i have some code..."
    Where is this code, you have not provided much info to go on.
    If you are using IO::Socket::INET have a look at the peeraddr() method:
    "Return the address part of the sockaddr structure for the socket on the peer host"

    This is from the documentation.

    Hope this helps.

    Martin

      Or even the peerhost() method if you want the IP address directly in the usual dotted-quad(x.x.x.x) notation.


      Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. -- Brian W. Kernighan
        sorry
        using use IO::Socket::INET;

        my $server = IO::Socket::INET->new( Proto => 'tcp', LocalPort => $serverport, Listen => SOMAXCONN, Reuse => 1); die "can't setup server" unless $server; my $remotehost; &writelog("$date: INFO: Server $0 started accepting clients connection +s"); while ($client = $server->accept()) { $client->autoflush(1); $remotehost = $client->peeraddr; } But i get this in the log 01/11/2005/ 14:42: INFO: New client connection from Μφ