I have a Java web application with Applets that access web services. These services are accessed through a specific hostname (example: services.webapp.com.br
) configured in the application. Knowing that it is the user's JVM that will execute the code related to the Applets life cycle, it is up to this JVM to translate the host services.webapp.com.br
into an IP address that will be effectively used by the services.
However, it can happen that the user can edit his Windows\System32\drivers\etc\hosts
and redirect the host services.webapp.com.br
to another IP that is not the address of my services, so the application will not be able to access them and an error will happen. >
I know that in addition to hosts
of Windows there are other ways to redirect traffic to a different IP, however, I want to cover this point because I know that my users usually use it.
In other words, I need to know at runtime if there is any entry for the host services.webapp.com.br
in the hosts
file of the user machine that is using my Applet to display an alarm if it is true. Is there an elegant way to do this implementation?
In a few hours of Google search, I saw that the only solution would be to read the contents of this file directly using the Java I / O libraries as in this example , because it is something of a low-level operating system and out of the scope of Java.
Sorry for not posting code, as my biggest question lies in the concept of implementation.