Created
September 26, 2016 16:04
-
-
Save ameshkov/5d8bb32f36b915d303be519eaff82538 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Determine if some other VPN is running | |
*/ | |
public static boolean isVpnConnected() { | |
try { | |
final List<NetworkInterface> interfaces = Collections.list(NetworkInterface.getNetworkInterfaces()); | |
for (final NetworkInterface networkInterface : interfaces) { | |
final String name = networkInterface.getDisplayName(); | |
final boolean isUp = networkInterface.isUp(); | |
LOG.info("Interface: {} connected = {}", name, isUp); | |
if (StringUtils.startsWithIgnoreCase(name, "tun") && isUp) { | |
return true; | |
} | |
} | |
} catch (SocketException ex) { | |
LOG.debug("Error while checking if other VPN is connected\n", ex); | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment