Java检测VPN代码

import java.net.NetworkInterface;
import java.util.Collections;
import java.util.Enumeration;

public class VPN {
    public VPN() {
    }

    public static boolean isVpnUsed() {
        try {
            Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();
            if (networkInterfaces != null) {
                for (T t : Collections.list(networkInterfaces)) {
                    if (t.isUp() && t.getInterfaceAddresses().size() != 0) {
                        if ("tun0".equals(t.getName()) || "ppp0".equals(t.getName())) {
                            return true;
                        }
                    }
                }
            }
        } catch (Throwable th) {
            th.printStackTrace();
        }
        return false;
    }
}
THE END
喜欢就支持一下吧
点赞5赞赏 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片

    暂无评论内容