简体   繁体   中英

same IP address for multiple computer

i tried to get the users ip address using php code:

$_SERVER["REMOTE_ADDR"];

and when i checked though the computer associated to the same network it provided the same ip address for all computer...why is it so. I was expecting distinct ip addresses. How can i get distinct ip address using php?

There are a limited number of IPV4 IP addresses. Consequently, most people who are not running public facing servers use Network Address Translation .

This will involve them using a computer on a LAN (with an IP in private address space such as 192.168.1.2) and a router with a LAN IP address and an Internet IP address that relays traffic between them and servers on the Internet.

Servers on the Internet will only ever see the Internet facing IP address of the router.

To see the private IP address you would have to run software inside the boundaries of the LAN. In theory you could pick up the address if you could persuade users run allow a signed Java applet to execute, but even then you could have issues if multiple IPs are in use. (eg I currently have a loopback IP, an ethernet IP, a Wi-Fi IP and am running two virtual machines which my workstation has an couple of IPs for them to connect to).

You have an ip for your server, a local network have an external ip(which is what you see). All computers on that network have their own internal ip.

when a computer connects to your server it does that trough the ip of the router/switch it's connected trough.

When you are in the same LAN, you will have the same IPv4 address if your router uses NAT (which most of them do). You can't do anything about it, it's just how it works. Note that if somebody is using IPv6, most of the times every computer has it's own unique IP address.

Little extra note: your router is keeping track of the outgoing connections, and thus making sure that every data package is getting to the right source (internal computer). There is no way on tracking that either, so you really have to work with that. But also note that using a 'normal IP address', with the code you are using, it's pretty unique. Maybe some users in the network have the same IP address, but it's a unique identifier for that specific network. Also note that people can have dynamic IPv4 addresses, that means that the IP address changes quite often. "Static" IP addresses are addresses that stay with the network. This is something that the ISP controls.

Your machines might be behind a network proxy server.

In this case, your web server is located outside your local network. It can only see the proxy server IP address from the server variable.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM