Java IP Address Get getIPV6AllAddresses(NetworkInterface ni)

Here you can find the source of getIPV6AllAddresses(NetworkInterface ni)

Description

Return all the ip V6 addresses associated with the ni

License

Apache License

Parameter

Parameter Description
ni network interface we are looking for

Exception

Parameter Description
IOException an exception

Return

the ip addresses, empty array of no ips

Declaration

public static Inet6Address[] getIPV6AllAddresses(NetworkInterface ni) throws IOException 

Method Source Code

//package com.java2s;
/*//from w  w w  .j  ava2 s . c o  m
 * Copyright (c) 2012-2017 ZoxWeb.com LLC.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

import java.io.IOException;

import java.net.Inet6Address;
import java.net.InetAddress;

import java.net.NetworkInterface;

import java.util.ArrayList;

import java.util.Enumeration;

public class Main {
    /**
     * Return all the ip V6 addresses associated with the ni
     * 
     * @param ni
     *            network interface we are looking for
     * @return the ip addresses, empty array of no ips
     * @throws IOException
     */
    public static Inet6Address[] getIPV6AllAddresses(String ni) throws IOException {
        return getIPV6AllAddresses(NetworkInterface.getByName(ni));

    }

    /**
     * Return all the ip V6 addresses associated with the ni
     * 
     * @param ni
     *            network interface we are looking for
     * @return the ip addresses, empty array of no ips
     * @throws IOException
     */
    public static Inet6Address[] getIPV6AllAddresses(NetworkInterface ni) throws IOException {
        ArrayList<Inet6Address> v = new ArrayList<Inet6Address>();
        for (Enumeration<InetAddress> e = ni.getInetAddresses(); e.hasMoreElements();) {
            InetAddress addr = e.nextElement();
            if (addr instanceof Inet6Address)
                v.add((Inet6Address) addr);
        }

        return v.toArray(new Inet6Address[v.size()]);

    }
}

Related

  1. getIPv4Address(NetworkInterface iface)
  2. getIPV4MainAddress(NetworkInterface ni)
  3. getIPv4MulticastGroup(int hash)
  4. getIPV4NetwprkOrder(String theIp)
  5. getIPV6AddrArray(String s)
  6. getIpv6List()
  7. getLanIPAddress()
  8. getLinuxIPAddress()
  9. getLocalAddresses(boolean ipv4only)