Skip to content

Instantly share code, notes, and snippets.

@ameshkov
Created September 26, 2016 16:04
Show Gist options
  • Save ameshkov/5d8bb32f36b915d303be519eaff82538 to your computer and use it in GitHub Desktop.
Save ameshkov/5d8bb32f36b915d303be519eaff82538 to your computer and use it in GitHub Desktop.
/**
* 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