美文网首页工作心得体会
whistle代理配置鉴权

whistle代理配置鉴权

作者: 魔王大柚子 | 来源:发表于2022-08-10 20:21 被阅读0次

    whistle查看抓包数据的页面,可以添加账号和密码,只需要在启动时,输入参数:

    w2 start -p yourport -n yourusername -w yourpassword。
    

    在进入页面时,就需要鉴权了

    代理接口需要授权
    设备ip白名单:
    一 按照插件 script:

    1. 安装Node: 官网下载安装最新版本(LTS和Stable都可以)

    2. 安装最新版的whistle

       npm install -g whistle
      
       # Mac、Linux用户可能需要加sudo
       sudo npm install -g whistle
      
      
    3. 安装script插件:

       w2 i whistle.script
      

    二 插件写入校验脚本


    image.png
    image.png
    exports.auth = async (req, options) => {
        // 给请求添加自定义头,必须与 `x-whistle-` 开头
        // 这样可以在插件的其他 hook 里面获取到该请求头(除了 http 请求的 reqRead 钩子)
        
      IPLIST=['xx.xx.xx.xx']
      if(IPLIST.indexOf(req.clientIp)!=-1){
        req.setHeader('x-whistle-test', '1111111111');
      }else{
         return false;
      }
        
        // return false; // 直接返回 403
    };
    

    三 规则中,加入脚本


    image.png

    收工~

    相关文章

      网友评论

        本文标题:whistle代理配置鉴权

        本文链接:https://www.haomeiwen.com/subject/wjbawrtx.html