In article 202005281646.34790.gary.stainburn@ringways.co.uk, Gary Stainburn gary.stainburn@ringways.co.uk wrote:
Hi all,
I can't believe that I can't find the answer to this one. I have a perl script which is called by xinetd.
I want that perl script to be able to detect the remote IP address of the caller.
I presumed that it would be an environment variable but I could be wrong. I've found reference to the ENV and PASSENV arguments for xinetd.conf but no examples, and no indication of what auguments to use.
In my script I have the following code:
foreach (keys %ENV) { print "$_=$ENV{$_}\n";}
but the only line I get back is:
XINETD_LANG=en_US
Works for me. Here are my details:
1. /usr/local/bin/args:
#!/usr/bin/perl
$i=1; while(defined($_ = shift)) { printf "ARGV[%d]="%s"\n",$i++,$_; } foreach $env (keys %ENV) { printf "ENV{%s}="%s"\n",$env,$ENV{$env}; }
2. /etc/xinetd.d/args:
service args { disable = no port = 54321 type = UNLISTED socket_type = stream wait = no user = root server = /usr/local/bin/args server_args = --test log_on_failure += USERID }
3. Results of telnet 127.0.0.1 54321:
# telnet 127.0.0.1 54321 Trying 127.0.0.1... Connected to localhost.localdomain (127.0.0.1). Escape character is '^]'. ARGV[1]="--test" ENV{CONSOLE}="/dev/console" ENV{PREVLEVEL}="N" ENV{SELINUX_INIT}="YES" ENV{LC_COLLATE}="en_US" ENV{RUNLEVEL}="3" ENV{LC_ALL}="en_US" ENV{previous}="N" ENV{LC_NUMERIC}="en_US" ENV{PWD}="/" ENV{LC_TIME}="en_US" ENV{LANG}="en_US" ENV{LC_MESSAGES}="en_US" ENV{runlevel}="3" ENV{INIT_VERSION}="sysvinit-2.86" ENV{SHLVL}="3" ENV{LC_MONETARY}="en_US" ENV{_}="/usr/sbin/xinetd" ENV{PATH}="/sbin:/usr/sbin:/bin:/usr/bin" ENV{vga}="773" ENV{REMOTE_HOST}="127.0.0.1" ENV{TERM}="linux" Connection closed by foreign host.
Notice the value of ENV{REMOTE_HOST}
Cheers Tony