0

Possible Duplicate:
How can a server find real client IP address?

I need to let my users find very quickly and easily their local (LAN) ip.

Our network has a squid proxy so all the users sit behind it (and this is a problem for internal ip detection: all php scrips I've tried are able - at best - to detect proxy's ip and not client's).

Any kind of language working on a LAMP server is welcome...

Also a simple EXE file on Windows could work as "plan b" but I couldn't find anything working.

Community
  • 1
  • 1
Pitto
  • 8,229
  • 3
  • 42
  • 51
  • Why not write a batch script to run ipconfig/ifconfig? – Rhys Jul 25 '12 at 13:57
  • I need this to show my average user (totally not computer savy) in a VERY easy way their ip so they can read it to me and I can use vnc or anything else to help them remotely. Of course telling on phone: click on start, select "execute", digit "cmd", then you have a big black windows... It'll work but it'll be a real pain :) Just asking them to go on our intranet website... Great! – Pitto Jul 25 '12 at 14:03

3 Answers3

1

Consider java applet loaded in browser. Since java uses its own virtual environment, it will be able to show local Ip address to the clients.

Good way to start i guess -> http://reglos.de/myaddress/MyAddress.html


And for Java to obtain IP: How can i check System IP Address/Host Name in Java?

This way you wont have to change current environment. Otherwise it will probably involve squid reconfiguration.


From the comments you have posted i can see that the purpose of presenting the IP to the client is to make them read it to you and allow you to connect remotely. You have also mentioned that running an app on a client side is an option. This immediately pushed me towards BGInfo http://technet.microsoft.com/en-us/sysinternals/bb897557.aspx - especially if the clients operating system is Windows.


The easy Java aplet to put on a page:

function myIP(){ var vi="uses java to get the users local ip number"
    var yip2=java.net.InetAddress.getLocalHost();   
    var yip=yip2.getHostAddress();
  return yip;
}//end myIP

alert("your machine's local network IP is "+ myIP())
Community
  • 1
  • 1
mnmnc
  • 374
  • 3
  • 14
  • Tasty! Any link and or suggestion to investigate further? (I am the poorest programmer ever) :) – Pitto Jul 25 '12 at 14:25
  • Try this one: http://reglos.de/myaddress/MyAddress.html – mnmnc Jul 25 '12 at 14:33
  • Package a Java applet and run a Java runtime on the client seems more work to me than a simple line in the Squid configuration – Raffaele Jul 25 '12 at 14:42
  • @Raffaele - you are of course correct in regards to the amount of work. Since OP did not provide the information if he is able to change the environment in any way, i have simply suggested the alternative. – mnmnc Jul 25 '12 at 14:44
  • The second alternative you suggest, a widget, is the best choice imho. The only reason why I didn't suggest it myself is that on low-end machines widgets may be resource hungry and it anyway it's a waste of resource to have this program always on just for the few times you need it – Raffaele Jul 25 '12 at 15:02
  • Of course a good option would be to run anything client side but this would force me to install "x" on all the clients (LOTS of them and no domain :/) --> install it manually --> bad – Pitto Jul 25 '12 at 15:02
  • Regarding the java option: (again: I'm the poorest programmer) a Java applet into a web page easily? – Pitto Jul 25 '12 at 15:06
  • @Pitto I have edited my answer and provided you with java applet. – mnmnc Jul 25 '12 at 16:21
  • Thanks a lot for your help! This means that I'd have to install Java on all clients? – Pitto Jul 25 '12 at 16:32
  • Yes. You can do id remotely if you got administrative right on all of the PCs. The java silent install is described here: http://java.com/en/download/help/silent_install.xml and remote execution can be done by using psexec -> http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx – mnmnc Jul 25 '12 at 16:35
  • That would be a LOT of administrative effort since not all the admin passwords are known and / or the same. I have a compiled (.exe) python script that works great but I can't use it because of installing python on everyclient. The only good solution is either 100% web (no add ons) or a simple .exe I can put in the download section of the website... Sorry :( – Pitto Jul 25 '12 at 18:27
1

Following @German Arlington's answer, I think your best bet is configuring Squid to send the X-Forwarded-For header along with HTTP requests:

If set to "on", Squid will append your client's IP address in the HTTP requests it forwards. By default it looks like:

X-Forwarded-For: 192.1.2.3

Then you will be able to read the ip address in PHP via apache_request_headers()

<?php
$headers = apache_request_headers();
echo $headers["X-Forwarded-For"];
?>
Raffaele
  • 20,627
  • 6
  • 47
  • 86
  • This solution sounds easy and straightforward! I've changed my squid parameter to "on" and restarted it and tried your code in a php page: sadly I get the proxy ip and not the client's :( – Pitto Jul 25 '12 at 14:44
  • This is a problem with Squid itself. Maybe a `header_replace` directive, or Apache is proxied itself, who knows. You could try describing your network topology here, but you'd better ask another question. To prove this answser is right, you could try with a fresh install of Squid. Anyway, check the logs – Raffaele Jul 25 '12 at 15:09
  • I've tried it with another Squid server we have and - sadly - it works... Our Apache is not proxified and I couldn't find any header_replace in squid.conf :( – Pitto Jul 25 '12 at 18:25
  • ps The not working squid has also dansguardian on it... Can this be the problem? – Pitto Jul 25 '12 at 18:33
  • It was my Dansguardian's fault! I've set in dansguardian.conf two parameters: forwardedfor = on and usexforwardedfor = on and it went great! Thanks a LOT :) – Pitto Jul 25 '12 at 18:40
0

You may be interested in

http://roshanbh.com.np/2007/12/getting-real-ip-address-in-php.html

and generally in http headers that should contain the information you are looking for

Germann Arlington
  • 3,315
  • 2
  • 17
  • 19