Skip to content

Instantly share code, notes, and snippets.

@nfisher
Created July 14, 2013 11:58
Show Gist options
  • Save nfisher/5994058 to your computer and use it in GitHub Desktop.
Save nfisher/5994058 to your computer and use it in GitHub Desktop.
import java.net.NetworkInterface;
import java.util.Enumeration;
public class NetIf {
public static void main(String [] args) {
try {
Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces();
while (en.hasMoreElements()) {
NetworkInterface nif = en.nextElement();
Enumeration<NetworkInterface> suben = nif.getSubInterfaces();
while (suben.hasMoreElements()) {
System.out.println(suben.nextElement().getName());
}
System.out.println(nif.getName());
}
} catch(Exception e) {
e.printStackTrace();
}
}
}
$ ifconfig -u
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384
# loopback device no status req'd
en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
status: active
p2p0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 2304
status: inactive
en3: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
status: inactive
$ java NetIf
en0
lo0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment