Optimized approach to check if a certain entry exists in the Windows hosts file

5

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.

    
asked by anonymous 04.08.2014 / 23:29

1 answer

3

If I may comment, this is an approach that may be considered fragile. A more experienced user will change routes directly on the router and leave the HOSTS file untouched.

Something safer would be to implement an encrypted token mechanism that only the two legitimate sides of the application could interpret. Thus, even if the HOSTS file is compromised, the client will only validate the connection if a valid token is received.

    
05.08.2014 / 00:43
How to disable and enable a network adapter with Delphi? ___ ___ erkimt Align text after image ______ qstntxt ___

Hello, I have a problem that I do not know how to solve. This is my situation:

ButIwantittolookthisway:

And like I said, I have no idea how to solve it.

And this is my code:

%pre%

Thank you.

    
______ azszpr30062 ___

While you treat the text as a single character string, no space. Of course your code will not partition the content and will not consecutively fit the base of a %code% . I imagine, you will not have a single giant word like that.

Instead of dealing with style, I applied classes. Some sincerely even unnecessary, there is how to lapid this code a bit. The value of the body can be modified according to the proportions it will treat.

CSS

%pre%

HTML

%pre%

JSFiddle

    
______ azszpr30058 ___

I've pasted your HTML into jsfiddle and left working as you wanted it to, but I noticed that it's a little complicated beyond what it should be, it might be simpler, like this:

%pre%

JSFiddle

Or better yet, delete inline styles and just use classes, it's much easier to modify and adjust later.

    
______ azszpr30066 ___

Here it depends a lot on the effect you want. If you want the text to wrap the image, use float as in the solutions that have already been presented. Now you want to make two columns, that is, keep the space underneath the empty image, so you can do this:

%pre%

Note that the width value can be set to any value but the sum of all width and margin can not exceed 100%. The width has to be even defined because by default the value of the width of the image and of the p is of 100% it makes the text stay under the image.

    
______ azszpr170973 ___

%code% in the image. simple and easy:)

    
___