Wednesday, October 7, 2015

IP address (local IP address) finder

This progran scans your IP address and the hostname then displays both of them. This program throws an exception "unknown host exception."

import java.net.InetAddress; import java.net.UnknownHostException; public class IpAddressFinder { public static void main(String[] args) { // Get the local host name and the IP address. try { InetAddress addr = InetAddress.getLocalHost(); System.out.println("Local Host Name: " + addr.getHostName()); System.out.println("IP Address : " + addr.getHostAddress()); } catch (UnknownHostException e) { e.printStackTrace(); } } }