Thu Oct 28 2021

Network Interface Info

File Name: network-interface-info.java

/* Get Network Interface details of the Local machine */
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Collections;
import java.util.Enumeration;

public class networkParameter {
	public static void main(String args[]) throws SocketException {

		/* Collect network interface details */
		Enumeration<NetworkInterface> netInf = NetworkInterface.getNetworkInterfaces();
		for (NetworkInterface netInfo : Collections.list(netInf)) {

			/* Display network interface details */
			System.out.println("Display name: "+ netInfo.getDisplayName());
			System.out.println("Name: "+ netInfo.getName());
			Enumeration<InetAddress> ipAddresses = netInfo.getInetAddresses();
			for (InetAddress ipAddress : Collections.list(ipAddresses))
				System.out.println("IP Address: "+ inetAddress);
			System.out.println("\n");
		}
	}

}




/* Output */
Display name: eth0
Name: eth0
IP Address: /fe80:0:0:0:eea8:6bff:fef5:1e5f%eth0
IP Address: /192.168.1.1

Display name: lo
Name: lo
IP Address: /0:0:0:0:0:0:0:1%eth0
IP Address: /127.0.0.1

We use cookies to improve your experience on our site and to show you personalised advertising. Please read our cookie policy and privacy policy.