Java Network Interface Get getFreeTunnelInterface()

Here you can find the source of getFreeTunnelInterface()

Description

Return the first free tunnel interface.

License

Open Source License

Return

Interface name.

Declaration


public static String getFreeTunnelInterface() 

Method Source Code

//package com.java2s;
/*// w  w w  .ja v a  2s.  c  om
 * ISABEL: A group collaboration tool for the Internet
 * Copyright (C) 2009 Agora System S.A.
 * 
 * This file is part of Isabel.
 * 
 * Isabel is free software: you can redistribute it and/or modify
 * it under the terms of the Affero GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Isabel is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * Affero GNU General Public License for more details.
 * 
 * You should have received a copy of the Affero GNU General Public License
 * along with Isabel.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.net.NetworkInterface;

import java.util.Enumeration;

public class Main {
    /**
     * Return the first free tunnel interface.
     * 
     * @return Interface name.
     */

    public static String getFreeTunnelInterface() {
        try {
            Boolean free = false;
            int i;
            for (i = 0;; i++) {
                NetworkInterface interfaz;
                free = true;
                for (Enumeration interfaces = NetworkInterface
                        .getNetworkInterfaces(); interfaces
                        .hasMoreElements();) {
                    interfaz = (NetworkInterface) interfaces.nextElement();
                    if (interfaz.getName().equals("tun" + i)) {
                        free = false;
                    }
                }
                if (free) {
                    return "tun" + i;
                }
            }

        } catch (Exception e) {
            System.out
                    .println("TunnelUtils - Error getting next free tun interface.");
            return null;
        }
    }
}

Related

  1. getBroadcast()
  2. getCustomMACFormat(NetworkInterface inte)
  3. getDefaultInterface()
  4. getDefaultNetworkInterface()
  5. getFirstMACAdress()
  6. getGlobalI()
  7. getGlobalInterfaces()
  8. getGoodNetworkInterfaces()
  9. getHostnameFromNetworkInterface()