Here you can find the source of getIPV6AllAddresses(NetworkInterface ni)
Parameter | Description |
---|---|
ni | network interface we are looking for |
Parameter | Description |
---|---|
IOException | an exception |
public static Inet6Address[] getIPV6AllAddresses(NetworkInterface ni) throws IOException
//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()]); } }