模拟netcat -e
如何使用没有 -e
选项的 netcat 版本模拟 netcat -e
?
我需要远程触发命令。我可以使用 netcat 来完成此操作 - 无需 -e
:
#!/bin/bash
netcat -l 8080; myCommand.sh
这可以解决问题,但是我想根据命令的成功或失败来回复客户端(有一种类似于 REST 的界面)。
我怎么能这么做呢?
谢谢!
How can I emulate netcat -e
with a version of netcat that does not have the -e
option ?
I need to trigger a command remotely. I can do it with netcat - without -e
:
#!/bin/bash
netcat -l 8080 ; myCommand.sh
That would do the trick, but I would like to reply to the client depending on the success or failure of the command (to have a kind of REST - like interface).
How could I do that ?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
然后只需 nc servername 2600 和 ./script.sh
使用 ctrl+c 杀死客户端
Then just nc servername 2600 and ./script.sh
kill the client with ctrl+c
最好的方法是切换到支持它的 netcat 版本。正确地在 Debian/Ubuntu IIRC 上,您应该使用 netcat traditional,而不是 netcat openbsd:
您可以选择明确指定您需要的版本:(
注意微妙之处选项使用的差异)。正如你所看到的(如下) nc.traditional 可以作为独立的二进制文件运行,仅依赖于 libc 和 linux 本身,所以如果你没有安装权限,你应该能够只需删除独立的二进制文件< /strong> 某处(当然是具有
exec
权限的文件系统)并像HTH一样运行它
The best way is to switch to the version of netcat that does support it. On Debian/Ubuntu IIRC correctly you should use netcat traditional, not netcat openbsd:
You will have the option of specifying explicitely which version you require:
(note the subtle differences in option usage). As you can see (below) nc.traditional can be run as a standalone binary, depending on only libc and linux itself, so if you don't have installation permissions, you should be able to just drop the standalone binary somewhere (a filesystem with
exec
permission of course) and run it likeHTH