V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
爱意满满的作品展示区。
kingddc314
V2EX  ›  分享创造

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

  •  
  •   kingddc314 ·
    six-ddc · 2017-04-24 21:15:23 +08:00 · 3036 次点击
    这是一个创建于 2530 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

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

    • 正常的 Shell 操作,输出重定向到 Server 终端
    • 读取当前 HTTP 请求内容
    • 自定义 Response 返回

    我们可以这样玩:

     # 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

    11 条回复    2017-07-08 21:29:53 +08:00
    hand515
        1
    hand515  
       2017-04-24 21:21:25 +08:00
    我看标题以为是用 shell 写了个 http 服务端
    song940
        2
    song940  
       2017-04-24 21:55:00 +08:00 via iPhone
    @hand515 我也以为是,因为我之前确实写了个。。
    https://github.com/song940/shell-scripts/blob/master/http-server
    song940
        3
    song940  
       2017-04-24 21:56:47 +08:00 via iPhone
    @hand515 大概效果就是,如果可执行就执行并返回结果( CGI ),不能执行就输出原文。
    whileFalse
        4
    whileFalse  
       2017-04-24 21:57:05 +08:00
    脑洞不错。
    yangyanggnu
        5
    yangyanggnu  
       2017-04-24 21:59:57 +08:00
    command injection :p
    ryd994
        6
    ryd994  
       2017-04-24 23:06:07 +08:00 via Android
    这该算重新发明 CGI 么………
    Tink
        7
    Tink  
       2017-04-25 07:51:33 +08:00 via iPhone
    这个还挺好玩的,能方便不少
    sunjourney
        8
    sunjourney  
       2017-04-25 09:04:38 +08:00
    说好的 shell 呢
    Tink
        9
    Tink  
       2017-04-25 09:50:25 +08:00
    最好能一个进程实现多个 shell commands 就好了
    gyorou
        10
    gyorou  
       2017-04-25 15:17:13 +08:00
    突然发现, CGI 原来已经是 20 多年前的东西了。。。
    mingyun
        11
    mingyun  
       2017-07-08 21:29:53 +08:00
    记得好像有个 Python 版的 httpbin
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   997 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 22:19 · PVG 06:19 · LAX 15:19 · JFK 18:19
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.