I need help using Inet address to make a internet usage log viewer. I have found a program to change IP addresses to a site URL. However it is not working correctly. help to rectify this problem will be greatly appreciated.
Below is the code that i have thus far.
import java.net.*;
class Url001{
public static void main(String[] args){
try{
System.out.println(
"Get and display IP address of URL by name");
InetAddress address = InetAddress.getByName(
"www.hotmail.com");
System.out.println(address);
System.out.println(
"Do reverse lookup on the IP address");
//Extract the IP address from the string to the right
// of the /. Then provide the IP address as a string
// to the getByName() method.
int temp = address.toString().indexOf('/');
address = InetAddress.getByName(
address.toString().substring(temp+1));
System.out.println(address);
System.out.println(
"Get and display current IP address of LocalHost");
address = InetAddress.getLocalHost();
System.out.println(address);
System.out.println(
"Do reverse lookup on current " +
"IP address of LocalHost");
temp = address.toString().indexOf('/');
address = InetAddress.getByName(
address.toString().substring(temp+1));
System.out.println(address);
System.out.println(
"Get and display current name of LocalHost");
System.out.println(address.getHostName());
System.out.println(
"Get and display current IP address of LocalHost");
//Get IP address as an array of bytes.
byte[] bytes = address.getAddress();
//Convert IP address bytes to unsigned values
// and display separated by spaces.
for(int cnt = 0; cnt < bytes.length; cnt++){
int uByte =
bytes[cnt] < 0 ? bytes[cnt] + 256 : bytes[cnt];
System.out.print(uByte + " ");
}//end for loop
System.out.println();
}catch(UnknownHostException e){
System.out.println(e);
System.out.println("Must be online to run properly.");
}//end catch
}//end main
}//end class Url001
and this is the Expected output
Get and display IP address of URL by name
www.hotmail.com/166.63.208.155
Do reverse lookup on the IP address
www.hotmail.com/166.63.208.155
Get and display current IP address of LocalHost
des-025/10.0.0.63
Do reverse lookup on current IP address of LocalHost
des-025/10.0.0.63
Get and display current name of LocalHost
des-025.tres-uk.co.uk
Get and display current IP address of LocalHost
10 0 0 63
However this is the output that i am recieving
Get and display IP address of URL by name
www.hotmail.com/166.63.208.155
Do reverse lookup on the IP address
/166.63.208.155
Get and display current IP address of LocalHost
des-025/10.0.0.63
Do reverse lookup on current IP address of LocalHost
/10.0.0.63
Get and display current name of LocalHost
des-025.tres-uk.co.uk
Get and display current IP address of LocalHost
10 0 0 63
Any help would be greatly recieved, Thank you for your time.
Regards
Timothy Jeffreys