Remote IP to script over inetd

Daniel O'Callaghan danny at
Mon Mar 25 22:28:25 UTC 2013

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.



More information about the freebsd-questions mailing list