Here you can find the source of getPublicInterface()
public static NetworkInterface getPublicInterface()
//package com.java2s; //License from project: Apache License import java.net.Inet6Address; import java.net.InetAddress; import java.net.NetworkInterface; import java.net.SocketException; import java.util.Enumeration; public class Main { public static NetworkInterface getPublicInterface() { Enumeration<NetworkInterface> nets; try {//from w w w . j av a2s . c o m nets = NetworkInterface.getNetworkInterfaces(); } catch (SocketException e) { return null; } NetworkInterface netinf; while (nets.hasMoreElements()) { netinf = nets.nextElement(); Enumeration<InetAddress> addresses = netinf.getInetAddresses(); while (addresses.hasMoreElements()) { InetAddress address = addresses.nextElement(); if (!address.isAnyLocalAddress() && !address.isMulticastAddress() && !(address instanceof Inet6Address)) { return netinf; } } } return null; } }