Remote IP to script over inetd
Daniel O'Callaghan
danny at clari.net.au
Mon Mar 25 22:28:25 UTC 2013
Hi Radek,
On 25/03/2013 10:09 PM, Radek Krejc(a wrote:
> #!/bin/sh
> echo $REMOTEHOST
getpeername() info is not available in Bourne shell directly.
You need to use perl or C or ....
So you can do something like this:
----------------------
#!/usr/bin/perl
# Example code from http://perldoc.perl.org/functions/getpeername.html
use Socket;
$hersockaddr = getpeername(SOCK);
($port, $iaddr) = sockaddr_in($hersockaddr);
$herhostname = gethostbyaddr($iaddr, AF_INET);
$herstraddr = inet_ntoa($iaddr); # $herstraddr is of form
"12.34.56.78"
# 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/redirects.sh $herstraddr";
exec($cmd);
----------------------
PS, if you are just sending an HTTP redirect or similar, you don't need
to run the script as root.
Cheers,
Danny
More information about the freebsd-questions
mailing list