autojs之是否使用了代理抓包

let r = isWifiProxy(context);
if (r) {
    
    
  log("有 代理");
} else {
    
    
  log("没有 代理");
}

function isWifiProxy(context) {
    
    
  importClass(android.os.Build);
  importClass(android.text.TextUtils);
  IS_ICS_OR_LATER = Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH;
  let proxyAddress;
  let proxyPort;
  if (IS_ICS_OR_LATER) {
    
    
    proxyAddress = java.lang.System.getProperty("http.proxyHost");
    portStr = java.lang.System.getProperty("http.proxyPort");
    proxyPort = java.lang.Integer.parseInt(portStr != null ? portStr : "-1");
  } else {
    
    
    proxyAddress = android.net.Proxy.getHost(context);
    proxyPort = android.net.Proxy.getPort(context);
  }
  return !TextUtils.isEmpty(proxyAddress) && proxyPort != -1;
}

// //通知Java您要通过代理进行连接
// System.getProperties().put("proxySet", "true");
// //指定代理所在的服务器
// System.getProperties().put("proxyHost", "myProxyMachineName");
// //指定代理监听的端口
// System.getProperties().put("proxyPort", "85");

// connection = url.openConnection();
// password = "username:password";
// encodedPassword = base64Encode(password);

// connection.setRequestProperty("Proxy-Authorization", encodedPassword);
// props = System.getProperties();
// props.put("http.proxyHost", "192.168.0.150");
// props.put("http.proxyPort", "808");

关注微信公众号, 查看更多教程
AutoJsPro教程
在这里插入图片描述

QQ交流群
747748653

码字不易,但求一赞,江湖再会。


追加isVpn函数

function isVPN() {
    
    
  try {
    
    
    var niList = java.net.NetworkInterface.getNetworkInterfaces();
    if (niList) {
    
    
      var VPN;
      var arry = java.util.Collections.list(niList).toArray();
      for (ary = 0; ary < arry.length; ary++) {
    
    
        if (!arry[ary].isUp() || arry[ary].getInterfaceAddresses().size() == 0) {
    
    
          continue;
        }
        if (arry[ary].getName().search("tun0") !== -1 || arry[ary].getName().search("ppp0") !== -1) {
    
    
          VPN = true;
          return true;
        } else {
    
    
          VPN = false;
        }
      }
      return VPN;
    }
  } catch (error) {
    
    }
}
log(isVPN());

禁止跳转, 就是禁止vpn抓包

var okHttpClient = new okhttp3.OkHttpClient()
  .newBuilder()
  .followRedirects(false) //禁止自动跳转
  .followSslRedirects(false)
  .build();


检查vpn和禁止跳转的作者是:
作者是掌玩小子粉丝群的Code

猜你喜欢

转载自blog.csdn.net/snailuncle2/article/details/113763682
今日推荐