More you share, more you have!!!

More you share, more you have!!!

Find out IP address of remotely located machine/system in Java environment

ip-address-java-remote


Q.Write a program to find out ip address of remote computer.

Source Code:->

import java.net.*;
class Inet1
{
public static void main(String args[]) throws
UnknownHostException
{
InetAddress Address = InetAddress.getLocalHost();
System.out.println(Address);
Address = InetAddress.getByName("starwave.com");
System.out.println(Address);
InetAddress SW[] = InetAddress.getAllByName("www.nba.com");
for (int i=0; i<SW.length; i++)
System.out.println(SW[i]);

byte[] addr=new byte[4];
              addr[0]=(byte)209;
              addr[1]=(byte)191;
              addr[2]=(byte)93;
              addr[3]=(byte)53;                
              InetAddress ip=InetAddress.getByAddress(addr);
System.out.println(ip);
}
}


Output:->


D:\student>javac Inet1.java

D:\student>java Inet1

PL10/172.16.23.10
starwave.com/199.181.132.250
www.nba.com/203.106.85.137
www.nba.com/203.106.85.136







Share on Google Plus
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment