Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 26 Mar 2013 09:27:59 +1100
From:      "Daniel O'Callaghan" <>
Subject:   Re: Remote IP to script over inetd
Message-ID:  <>
In-Reply-To: <>
References:  <>

Next in thread | Previous in thread | Raw E-Mail | Index | Archive | Help
Hi Radek,

On 25/03/2013 10:09 PM, Radek Krejc(a wrote:
> #!/bin/sh

getpeername() info is not available in Bourne shell directly.
You need to use perl or C or ....

So you can do something like this:



    # Example code from
    use Socket;
         $hersockaddr    = getpeername(SOCK);
         ($port, $iaddr) = sockaddr_in($hersockaddr);
         $herhostname    = gethostbyaddr($iaddr, AF_INET);
         $herstraddr     = inet_ntoa($iaddr);   # $herstraddr is of form

    # Now you know the remote IP address, do what we want to do
    # eg run a shell script and put IP into $1
    $cmd = "/root/ $herstraddr";


PS, if you are just sending an HTTP redirect or similar, you don't need 
to run the script as root.



Want to link to this message? Use this URL: <>