0

Suppose I have to implement a java program which has a capability to read the dynamic IP address of the particular Device.Is it possible in JAVA.

vijeshtd
  • 1
  • 1
  • 1
    *"I hope the sample code.."* ..has polka dots? It seems you forgot to finish that statement. But if it was going to end with *"..can be supplied"* note that does not go down well around Stack Overflow. SO is not a code generation machine. – Andrew Thompson Jan 17 '14 at 08:26

2 Answers2

0

If your device is on the internet, you will have to make a client-server application. The client will be install on the device and push his IP to the server each time the ip is changing.

You can check also utilities like "dyndns.com" and "no-ip.com". These utilities can provide a domain name to an dynamic IP.

beny1700
  • 284
  • 1
  • 4
  • 10
  • how can i read the ip address and how can i check whether the ip is changing or not?.is any built in classes is used in java? – vijeshtd Jan 17 '14 at 09:08
0
  1. As mentioned earlier try to provide some sample code or be more specific

  2. Get a java book and read the concept of TCP/IP networking.

  3. You may try the following code to get the local ip (LAN):

import java.net.InetAddress;

import java.net.UnknownHostException;

public class IP {

public static void main(String[] args) throws UnknownHostException {
    String ip=InetAddress.getLocalHost().getHostAddress();
    System.out.println("My IP address "+ip);
}

}

soulemane moumie
  • 1,005
  • 1
  • 14
  • 26
  • how can i check whether the ip is public or private ? – vijeshtd Jan 17 '14 at 09:22
  • This code will just give you the ip of the subnetwork. If you are behind a router (NAT) this will never work. You will have tu use an external webservice to get the REAL public IP. – beny1700 Jan 17 '14 at 10:19
  • The Dynamic IP address is WAN address is provided by your ISP. Generally it keeps changing each time you connect to the Internet. The conversion from the WAN to LAN is achieved by your router. Now if your behind a router you may always get the routers ip address as your default gateway. If you can execute some windows cmd like **ipconfig/all** using java as here http://stackoverflow.com/questions/4157303/how-to-execute-cmd-commands-via-java you can get some useful informations. – soulemane moumie Jan 18 '14 at 12:33