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

小轮子,获取外网 IP 和一些杂七杂八的玩意

  •  
  •   AlwaysBehave · 2017-08-29 15:00:56 +08:00 · 3143 次点击
    这是一个创建于 2403 天前的主题,其中的信息可能已经有所发展或是发生改变。

    有业务需要本地客户端看外网 IP,就做了一个小轮子(后面才看到 https://ip.sb ,但是做都做了 233,就当记录一下吧)

    地址的作用都是等同的,区别就是 ga 和 ml 都强制 https,cf 没有

    • 功能

      • IP Address In Plain Text
        • 直接访问即可,或者命令行 curl https://whatip.ga
        • /json 获取 JSON 格式
    • 顺便做了一点其他(没卵用)的……

      • /ping
        • 返回 pong
      • /base64/{content} or /?base64={content}
        • 转换 base64
        • 解密 /decode?base64={content} or /base64/{content}/decode
      • /generate_204 or /204
        • header 204 no content
      • /to/{base64}
        • 发送 302 跳转到 base64 编码后的地址,等同-> Location: //{Decoded Content}
        • /to/{base64}/http /to/{base64}/https{Decoded Content} 加上前缀
        • /to/{base64}/origin 等同-> Location: {Decoded Content}

    部署在 Hostker 上面,速度还是不错的,有比较冷门需求的就拿去玩玩咯
    没有留任何记录(懒),Apache2 的访问记录除外(这个也不会去看的)
    还不支持 IPV6,找时间会加上

    第 1 条附言  ·  2017-08-31 11:01:49 +08:00

    还有两个小功能,用来测试用也挺好

    • getHeader
      • 以JSON格式返回当前收到的Header信息
    • getUserAgent
      • 以Plain text返回当前的UserAgent

    提示:抑制了所有的错误信息,如果收到空白,除了可能是输入不对,也可能是500,这里还会有多一点处理 Written in PHP,Single File(自己简单打包了一下REQUEST_URL)

    https://github.com/HFIProgramming/whatip

    6 条回复    2017-08-31 10:36:37 +08:00
    nowgoo
        1
    nowgoo  
       2017-08-29 15:57:35 +08:00
    还是 ifconfig.io 比较符合直觉。
    AlwaysBehave
        2
    AlwaysBehave  
    OP
       2017-08-30 00:14:57 +08:00
    @nowgoo 你说的是 ifconfig.co 吗,io 访问真的有点慢的样子(
    mooncakejs
        3
    mooncakejs  
       2017-08-30 11:32:04 +08:00
    再推荐一个轮子 https://httpbin.org/
    Thiece
        4
    Thiece  
       2017-08-30 20:02:10 +08:00 via iPhone
    hostker 越来越慢了😂
    AlwaysBehave
        6
    AlwaysBehave  
    OP
       2017-08-31 10:36:36 +08:00
    @jamesliu96 233,不过一般是 cli 在用
    浏览器默认返回 escape 字符,无 UserAgent,curl,wget 会返回 Raw
    多谢提醒
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3077 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 14:35 · PVG 22:35 · LAX 07:35 · JFK 10:35
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.