我可以使用 netcat 来运行带有参数的 PHP CLI 吗?

发布于 2024-09-27 22:28:40 字数 252 浏览 0 评论 0原文

我正在尝试创建一个调试侦听器,该侦听器侦听端口上的数据字符串并将其作为参数转发到 php 脚本。如何指定端口的输入应用作参数?

例如:远程设备发送一个带有逗号分隔值 value1,value2,value3 的字符串,我想运行命令 php file.php value1,value2,value3并具有 $_SERVER["argv"][1] 中使用的值。

任何帮助将不胜感激!

I'm trying to create a debug listener that listens on a port for a data string and forwards it to a php script as an argument. How can I specify that the input to the port should be used as an argument?

For example: The remote device send a string with comma separated values value1,value2,value3 and I'd like to run the command php file.php value1,value2,value3 and have the values used in $_SERVER["argv"][1].

Any help would be appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

忘年祭陌 2024-10-04 22:28:40

也许是这样的?发送的每一行都将运行 PHP 脚本的单独调用。注意一旦连接关闭netcat就会退出;有些版本有一个标志,告诉它返回监听。或者您可以将整个事情包装在 while 循环中,或者您可以查看 inetd 或 xinetd 而不是 netcat,尽管这些可能有点重量级。

nc -l myport | while read line ; do php file.php "$line" ; done

Something like this, maybe? Every line sent will run a separate invocation of the PHP script. Note that netcat will quit once the connection is closed; some versions have a flag that tells it to go back to listening. Or you could wrap the whole thing in a while loop, or you could look into inetd or xinetd instead of netcat, though those might be a bit heavyweight.

nc -l myport | while read line ; do php file.php "$line" ; done
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文