简体   繁体   English

使用Shell脚本获取并打印客户端的LOCAL IP地址--Apache2 CGI / Bin

[英]Get and print Client's LOCAL IP address with Shell Script - Apache2 CGI/Bin

I've configured Apache2 with the cgi-bin directory so I can run shell scripts from my webserver. 我已经使用cgi-bin目录配置了Apache2,因此我可以从我的web服务器运行shell脚本。 I need to figure out a way for the shell script to read the connecting LOCAL ip address (for example 192.168.123.100) of the client, and then print it in the shell script (using echo, I'm guessing). 我需要找出一种方法让shell脚本读取客户端的连接LOCAL IP地址(例如192.168.123.100),然后将其打印在shell脚本中(使用echo,我猜)。

Here's a sample scenario of what I'd like to have happen. 这是我想要发生的事件的示例场景。

Client (with local IP of 192.168.123.100) connects to server (some other local IP, for example 192.168.123.122) and client executes the shell script in the cgi-bin directory. 客户端(本地IP为192.168.123.100)连接到服务器(某些其他本地IP,例如192.168.123.122),客户端在cgi-bin目录中执行shell脚本。 The shell script somehow reads the client's local IP address (192.168.123.100), and the prints it in the resulting output. shell脚本以某种方式读取客户端的本地IP地址(192.168.123.100),并将其打印在结果输出中。

Is this at all possible? 这是可能吗?

Thanks for any and all help! 感谢您的帮助!

它们的IP地址应该在变量$REMOTE_ADDR可用。

In addition to $REMOTE_ADDR you can get many other interesting information. 除了$ REMOTE_ADDR,您还可以获得许多其他有趣的信息。 See: http://www.cgi101.com/book/ch3/text.html 见: http//www.cgi101.com/book/ch3/text.html

Note, that if the client is using proxy or NAT, then you will see only the NAT or proxy server as a remote host. 请注意,如果客户端使用代理或NAT,则您将只看到NAT或代理服务器作为远程主机。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM