[英]Solaris10: How to get the remote end IP address in inted-started bash script?
On a Solaris 10 host there is an inetd service configured to start a bash script when it it gets an incoming TCP connection to a pre-configured port/service. 在Solaris 10主机上,有一个inetd服务,该服务配置为在bash脚本获得与预先配置的端口/服务的传入TCP连接时启动bash脚本。 Is there a way to find the IP address of the remote client in the invoked bash script?
有没有办法在调用的bash脚本中找到远程客户端的IP地址?
If I was using the GNU version of inetd I would use the --environment
command line flag. 如果我使用的是inetd的GNU版本,则将使用
--environment
命令行标志。 But I am using the default Solaris version of inetd/inetadm, which does not seem to support this flag. 但是我使用的是默认的Solaris版本的inetd / inetadm,它似乎不支持此标志。 Is there a Solaris equivalent of this setting?
是否有与该设置等效的Solaris?
I also assume that getpeername(2)
invoked on the fd
of 0 ( stdin
) or 1 ( stdout
) would have returned the desired information but I am running a bash script and I don't seem to find a way to invoke an equivalent of getpeername(2)
from bash. 我还假设在0(
stdin
)或1( stdout
)的fd
上调用的getpeername(2)
将返回所需的信息,但是我正在运行bash脚本,而且我似乎找不到找到等效方法的方法。来自bash的getpeername(2)
。
Is my only option to invoke a C-wrapper that would do getpeername(2)
, store it in an environment variable (or a command-line argument), and invoke the main bash script? 我唯一的选择是调用执行
getpeername(2)
的C-wrapper,将其存储在环境变量(或命令行参数)中,然后调用主bash脚本吗?
Thank you! 谢谢!
You can invoke getpeername from a Perl one-liner: 您可以从Perl一线式调用getpeername :
perl -le 'use Socket; ($port,$addr) = sockaddr_in(getpeername(STDIN)); print inet_ntoa($addr);'
Wrap in backticks or whatever to run from a shell script. 包装在反引号中或从shell脚本运行的任何东西。
You can get them by parsing pfiles
output, something like: 您可以通过解析
pfiles
输出来获取它们,例如:
pfiles $$ | grep peername | head -1 | nawk '{print $3}'
Edit: 编辑:
Here is a lighter way in reply to Nemo's right comment about the number of processes launched: 这是回应Nemo对启动的进程数的正确评论的一种简便方法:
pfiles $$ | nawk '/peername/ {print $3;exit}'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.