Java IpAddressLookup simple class

Share This:

import java.net.*;
import java.util.*;
public class IpAddressLookup {

public static void main(String[] args) {
try
{

System.out.print(“Please enter the address : “);
Scanner Sc = new Scanner(System.in);
String host= Sc.next();
InetAddress PC = InetAddress.getByName(host);

String hostname = PC.getHostName();
byte[] signed = PC.getAddress();
System.out.println(“Hostname is : ” + hostname);
System.out.println(“Signed address is ” + signed);
int unsigned;
System.out.println();
System.out.print(“IP Address is : “);

for(int i=0; i<signed.length;i++)
{
unsigned = signed[i] < 0 ? signed[i] + 256 : signed[i];

System.out.print(unsigned + “.”);
}
System.out.println();
}
catch (UnknownHostException e){
System.out.println(“Can’t find the IP Address or the hostname”);
}}}

Leave a comment

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload the CAPTCHA.