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 分享