views:

29

answers:

1

Hello,

I've donne a web app with Spring/GWT that uses Flash to upload files.

When I send an ajax request with GWT and try to get the user ip address, I get an ipv4 address like: 127.0.0.1

but when I upload my files with flash (and so a post request on the same webapp) I get an ipv6 address 0:0:0:0:0:0:0:1

I use the same code to get the user ip which is:

ServletRequestAttributes att = (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes();
att.getRequest().getRemoteAddr();

The problem is that I use a signature which uses the ip address to be sure that user can upload files (due to bug with session lost when uploading with flash) and the ip address changes when I use ajax or Post via flash.

What's the problem and how can I get the same ip format ?

thanks

+2  A: 

The reason is that the name you type in your browser has both ipv4 and ipv6 addresses. Browser chooses to use ipv4, flash chooses to use ipv6. There is nothing you can do about that on the server side (there is no way to convert).
However, you can change your DNS and make your name have only one address, either ipv4 or ipv6. You can also connect with a literal IP address (127.0.0.1), not a name (localhost).

unbeli
So, how can I identify user ? Without asking him to change various settings.
Jerome C.
what is the hostname you (client) uses? Is it localhost? Is it real hostname?
unbeli
localhost (for me when I debug) and real hostname (real client)
Jerome C.
ok, for your tests try using 127.0.0.1 instead of localhost. For clients, make sure that your real host name has either IPv4 or IPv6 address, not both.
unbeli
@Jerome. If you want to use 'localhost' you may want to add an entry to `/etc/hosts` `127.0.0.1 localhost`. If you are debugging on Windows this file is in a rather peculiar place: `C:\WINDOWS\system32\drivers\etc\hosts`.
Alexander Pogrebnyak
@Alexander Pogrebnyak isn't it always there?
unbeli
@unbeli. It is, but if you've never heard about it, then it's not the first place I would look into.
Alexander Pogrebnyak