写了一个用 Shell 写 HTTP 服务的工具

2017-04-24 21:15:23 +08:00
 kingddc314

工具效果是每接收到一个 HTTP Request ,就执行指定的 Shell Commands ,并返回内容

在脚本里面可以做这些事情:

我们可以这样玩:

 # Hello World
 $ httpbin :8080/hello -c 'httpbin add body world'
 $ curl http://127.0.0.1:8080/hello

 # 获取服务器进程
 $ httpbin 127.0.0.1:8080/ps -c "ps | httpbin add body"
 $ curl http://127.0.0.1:8080/ps
 
 # 获取本机 IP
 $ httpbin :8080/ip -c "httpbin get ip | httpbin add body"
 $ curl http://192.168.1.101:8080/ip
 
 # 下服务器文件
 $ httpbin :8080/download -c 'file=$( httpbin get form file); httpbin add body < $file'
 $ curl http://127.0.0.1:8080/download?file=/Users/haha/a.gif

Github : https://github.com/six-ddc/httpbin 来吧, F**k Me

3066 次点击
所在节点    分享创造
11 条回复
hand515
2017-04-24 21:21:25 +08:00
我看标题以为是用 shell 写了个 http 服务端
song940
2017-04-24 21:55:00 +08:00
@hand515 我也以为是,因为我之前确实写了个。。
https://github.com/song940/shell-scripts/blob/master/http-server
song940
2017-04-24 21:56:47 +08:00
@hand515 大概效果就是,如果可执行就执行并返回结果( CGI ),不能执行就输出原文。
whileFalse
2017-04-24 21:57:05 +08:00
脑洞不错。
yangyanggnu
2017-04-24 21:59:57 +08:00
command injection :p
ryd994
2017-04-24 23:06:07 +08:00
这该算重新发明 CGI 么………
Tink
2017-04-25 07:51:33 +08:00
这个还挺好玩的,能方便不少
sunjourney
2017-04-25 09:04:38 +08:00
说好的 shell 呢
Tink
2017-04-25 09:50:25 +08:00
最好能一个进程实现多个 shell commands 就好了
gyorou
2017-04-25 15:17:13 +08:00
突然发现, CGI 原来已经是 20 多年前的东西了。。。
mingyun
2017-07-08 21:29:53 +08:00
记得好像有个 Python 版的 httpbin

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/357087

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX