Help me with some PHP bitches
Moderator: Forum Moderators
-
- Zombie
- Posts: 2101
- Joined: February 20th, 2005, 21:31
Help me with some PHP bitches
Calling all codemonkeys...
I have a webpage that we use for diagnostics at work. We want the webpage to display the users IP address.
I've got it finding the users WAN ip no problemo, but its the LAN ip i would also like to get.
Something like 192.168.x.x thing from inside a network.
Am i correct in thinking that the internal IP never goes past a router? Otherwise, is there any way to make php run an IPCONFIG command on the client, and read an output file?
I have a webpage that we use for diagnostics at work. We want the webpage to display the users IP address.
I've got it finding the users WAN ip no problemo, but its the LAN ip i would also like to get.
Something like 192.168.x.x thing from inside a network.
Am i correct in thinking that the internal IP never goes past a router? Otherwise, is there any way to make php run an IPCONFIG command on the client, and read an output file?
-
- Weighted Storage Cube
- Posts: 7167
- Joined: February 26th, 2007, 17:26
- Location: Middle England, nearish Cov
Quick google returns:
http://uk3.php.net/manual/en/function.exec.php
And links and comments at the bottom of the page.
I'm only just learning php for a unit, but that looks rather useful.
I don't think IPConfig will write to a file though, you'll probably have to read the app's output from the console and do some string manipulation.
http://uk3.php.net/manual/en/function.exec.php
And links and comments at the bottom of the page.
I'm only just learning php for a unit, but that looks rather useful.
I don't think IPConfig will write to a file though, you'll probably have to read the app's output from the console and do some string manipulation.
-
- Morbo
- Posts: 19676
- Joined: December 10th, 2004, 21:53
- Contact:
Code: Select all
ipconfig /all > ipcfg.txt
so in console
Code: Select all
C:\>ipconfig /all > ipcfg.txt
The IP range you specified will never get routed by the internet. It is a reserved range with exactly that purpose.
I'm guessing a bit here, but I am imagining you've got various machines with 192.168.x.x/16 or similar, and then a shared connection to the internet using Network Address Translation. In this case, the internal IPs will never be seen by anything outside of your LAN.
If the web server was on an Intranet, this would of course be different.
At the end of the day, it is only possible to see the IP the machine chooses to use to communicate, so if a machine had two IPs, you would only see the one IP it chooses to use.
I would instead ask the user to run this in the run bar:
And email you the text file that appears on their desktop.
I'm guessing a bit here, but I am imagining you've got various machines with 192.168.x.x/16 or similar, and then a shared connection to the internet using Network Address Translation. In this case, the internal IPs will never be seen by anything outside of your LAN.
If the web server was on an Intranet, this would of course be different.
At the end of the day, it is only possible to see the IP the machine chooses to use to communicate, so if a machine had two IPs, you would only see the one IP it chooses to use.
I would instead ask the user to run this in the run bar:
Code: Select all
ipconfig /all > "%USERPROFILE%\desktop\ipconfig.txt"
Re: Help me with some PHP bitches
PHP is server side, it wont run anything on the client.ProfHawking wrote:is there any way to make php run an IPCONFIG command on the client, and read an output file?
Your options here are to write an ActiveX application (IE only), or write a java app - but you are going to have to contend with a shit load of security blocks. Java by default, and rightly so, allows fuck all access to the file system. You can agree to let it tho, I think.
Imagine if a website asked the client to run FDisk instead of IPConfig!
This may not be right but you will get the bitwise AND result of his local IP and his subnet mask, so if he has the rather usual local IP of 192.168.1.72 and the rather usual subnet mask of 255.255.255.0 then what you get is 192.168.1.0/24 (http://en.wikipedia.org/wiki/Subnet_Mask)
Bitwise AND explained:
255.255.255.0 = 11111111.11111111.11111111.00000000
192.168.1.0=11000000.10101000.00000001.01001000
Now we check at which places are bits both "1".
Bitwise AND explained:
255.255.255.0 = 11111111.11111111.11111111.00000000
192.168.1.0=11000000.10101000.00000001.01001000
Now we check at which places are bits both "1".
Code: Select all
11000000.10101000.00000001.01001000 AND
11111111.11111111.11111111.00000000
-----------------------------------
11000000.10101000.00000001.00000000
<3 boolean algebra - the best of all the maths.Baliame wrote:This may not be right but you will get the bitwise AND result of his local IP and his subnet mask, so if he has the rather usual local IP of 192.168.1.72 and the rather usual subnet mask of 255.255.255.0 then what you get is 192.168.1.0/24 (http://en.wikipedia.org/wiki/Subnet_Mask)
Bitwise AND explained:
255.255.255.0 = 11111111.11111111.11111111.00000000
192.168.1.0=11000000.10101000.00000001.01001000
Now we check at which places are bits both "1".
Code: Select all
11000000.10101000.00000001.01001000 AND 11111111.11111111.11111111.00000000 ----------------------------------- 11000000.10101000.00000001.00000000
The IP is just 4 bytes, in dotted decimal, and the /24 (or whatever) is just the sum of number of consecutive 1's in the binary subnet mask.
If you bitwise AND the IP and subnet, you get the network portion.
What this then means is any address starting the same as the network portion is routed directly (LAN) - and anything different is sent to the router (your 'default gateway' in windows) to be routed from there, probably around the Internet.
This is all academic when it gets to your router though, as that then gives it an entirely different source IP to that of your WAN interface, and tracks the tcp/ip session so it can send any replies it receives back to the correct internal PC.
In short, you're not gonna get the "LAN IP" without running an application on the "LAN PC" running with enough security rights to read the IP configuration and then transmit the results to some web server somewhere.
-
- Zombie
- Posts: 2101
- Joined: February 20th, 2005, 21:31
Ok, shame PHP cant run local things, like ipconfig then. I suppose it would be a massive security issue if it could.
And agreed, behind a router (thats doing its job) the lan ip is not going to get out. But that doesnt matter, as its only the client that needs to see it.
I have got it working with a bit of javascript:
Unfortunately this only works in firefox/opera. In IE6 or 7 it fails miserably. Unfortunately that seems to be the browser of choice for our client minions.
And agreed, behind a router (thats doing its job) the lan ip is not going to get out. But that doesnt matter, as its only the client that needs to see it.
I have got it working with a bit of javascript:
Code: Select all
<script>
var address = java.net.InetAddress.getLocalHost();
document.write("Your IP is: " + address);
</script>
-
- Morbo
- Posts: 19676
- Joined: December 10th, 2004, 21:53
- Contact: