2

I'm using Ruby on Rails as server-side framework, but I'm sure that solution is cross-platform.

I want to show user his real ip address. The application is deployed in corporate network. Most of users connect to application in straightforward way without proxy, NAT and etc. But some of them use proxy.

Now they see IP address of proxy server.

What is the best way to show them their real IP address?

As I could see It is not possible using only serve-side techniques. So solution should be something using JS (almost all users enable JS), Flash (about 80% users use it) or JAVA (about 50%). It would be great if solution was rails plugin, but it is not so important.

UPD. Unfortunately, X-Forwarded-For header has no interesting information.

UPD2. I want to show a local network ip (e.g. 192.168..).

UPD3. Almost all client browsers are Internet Explorer (7,8,6 versions)

petRUShka
  • 9,231
  • 12
  • 54
  • 86
  • It'd depend on what information is forwarded by the proxy. Some might use `X-Forwarded-For`, but if not (or if nothing similar) then you might be out of luck. – Brian Donovan Nov 20 '11 at 20:07
  • Unfortunately, X-Forwarded-For header has no interesting information. – petRUShka Nov 20 '11 at 20:10
  • Depending on the connection the user has, it is impossible. If the user's router is using a VPN for example. The router itself would use the VPN to tunnel the connection and the only IP the user has is his local network ip with the router. – felipemaia Nov 20 '11 at 20:14
  • Some users (a smaller part) uses VPN to enter whole corporate network. But in this case I'm interesting in their local ip address in VPN network. – petRUShka Nov 20 '11 at 20:19
  • petRUShka, please see the comment in my answer below. This is only possible if ALL users are on a corporate network where you can place a javascript file. – Chris Felstead Nov 20 '11 at 20:32
  • forget Javascript, this has been discussed numerous times http://stackoverflow.com/questions/391979/get-client-ip-using-just-javascript http://stackoverflow.com/questions/102605/can-i-lookup-the-ip-address-of-a-hostname-from-javascript etc – Oleg Mikheev Nov 29 '11 at 10:58
  • Have you tried searching this site? http://stackoverflow.com/questions/391979/get-client-ip-using-just-javascript – ccpizza Nov 30 '11 at 21:23
  • possible duplicate of http://stackoverflow.com/questions/5371020/how-can-a-server-find-real-client-ip-address – hafichuk Dec 01 '11 at 05:14

2 Answers2

2

Its an interest problem but I'm going to the bearer of bad news. No matter the platform or code you use, you will never get the solution to work 100%.

Let me explain, Some proxyies forward the originator ip in a header (usually x-forwarded-for). This isn't 100%.

Javascript at the client side MAY (pending security restrictions) give you the client ip, however, this could be a local network ip (e.g. 192.168..)

UPD: Please see my comments below for a javascript solution description that would work if all users are on a corporate network.

Chris Felstead
  • 1,170
  • 9
  • 19
  • Yes. I want to show local exactly network IP! What is the JS solution? – petRUShka Nov 20 '11 at 20:11
  • I stressed the MAY. Looking at the framework for javascript, it doesn't have access to the machine ip address. If the users are connecting on a corporate network, you could place the js file with the network and get the data sent up the final webserver. Otherwise, it's not possible. – Chris Felstead Nov 20 '11 at 20:18
  • To clarify on my above comment for future readers. If you had a javascript file in the local network, it can be referenced from the web app. Standard remote ip look up code would give the local ip address. This can then be sent to the webserver. – Chris Felstead Nov 20 '11 at 20:44
  • Thanks. But application in a local network too, so in my case your idea will not help... – petRUShka Nov 20 '11 at 20:50
  • The same network as your users? If so remote ip lookup works as is. If not, why won't my solution work? Can you provide more information? – Chris Felstead Nov 20 '11 at 21:00
  • Some users configured their browsers to use corporate proxy server. In this case I'm able to show only proxy server IP... – petRUShka Nov 21 '11 at 06:26
  • Could the proxy host the javascript file? If not, then I'm afraid what you are after simply isn't possible. – Chris Felstead Nov 21 '11 at 11:04
0

You could use node.js as a websocket server, and on the clientside have a javascript websocket application.

Once connected, you can read the IP out to be accessible by Ruby (via the filesystem api or something else).

Here's a simple error log application that has a good example of a Websocket server using node.js: http://gonzalo123.wordpress.com/2011/05/09/real-time-monitoring-php-applications-with-websockets-and-node-js/

As far as how websockets interact with proxies, a quick search I learned that securing the websocket with SSL will enable you to bypass proxies. (Ref: http://showmetheco.de/articles/2011/2/diving-into-html5-with-websockets-and-perl.html)

While this idea was off the top of my head, I can't do all the research for you but this should get you started to a potential solution.

BTW Websockets are an HTML5 feature, so your corporation may need to have everyone's browsers updated ^^.

Vigrond
  • 7,820
  • 4
  • 24
  • 43