简体   繁体   中英

Get Dynamic ip address Java?

I am using Java technology for my development. I need to find Dynamic allocated Ip address of system using previous allocated dynamic ip .

There are 2 scenarios for this:

1.In first I am storing previous IP in my database so need to find IP using previous IP.

2.When user connect any USB modem/Dongle then Dynamic IP changes automatically so how to get newly allocated IP with help of previous IP.

Till now I tried lots of things but won't get useful help regarding this. I want to find ip's only using java technology as I never work on such task.

It is not possible to find the system's current IP address based on what it was before. However, you should not need to do that. If your system is properly configured, then you should be able to find out what its IP address is ... independently of what it was before.

This Q&A deals with the question of finding your system's current IP address in Java. (Unfortunately, it can get a bit complicated if your system has multiple network interfaces and/or multiple IP addresses.)


On the other hand, if you are attempting to dynamically allocate or acquire an IP address for your machine, you are better of not doing this in Java. There are all sorts of things that need to be done at the system level (and on other systems) to make it work. (Read up on DHCP and how network configuration works for your operating system.)


i had stored all ips on server database but when my client IP Change how can Automatically update my server database IP uniquely.

I take it that you want to change the database entry for the client, but that you don't know what the old IP address of the client was.

Unless you have some other identifying characteristic for the client (eg a cookie value) I don't think it is possible. The new IP address won't tell you what the old IP address was, and there are no standard network services that will do this for you. (If you had access to the DHCP server logs, you may be able to figure it out. But those logs won't be available to a normal Java application. For a start, they will be on another machine ...)

Basically IP addresses are not stable identifiers for clients. If you need a stable (or trackable) identifier, you need to use something else; ie something other than IP addresses.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM