简体   繁体   中英

Get user ipv4 when client supports dual stack ipv4+ipv6

So I have a NGINX web server with php and I need a way to force all clients to connect over IPv4 if they have Dual Stack IPv4+IPv6, and still be able to connect if they support only IPv6 OR only IPv4.

How would I go about this?

If not possible, is there anyway I could use java script to get a client's IPv4 (when connecting through IPv6) and post it to a url?

You can't control client behaviour and pushing a client to a specific IP address is a bad idea. And clients might even change between protocols during a single session. Either because their mobile device connected to a different network or because how browsers implement the happy eyeballs standard. There are so many different technologies that are used to connect users to the IPv4 and IPv6 internets that second guessing what they choose is going to end in tears.

Just make your service equally accessible over both protocols and implement it so that the protocol doesn't matter. That's the only sustainable solution.

To get the user's IPv4 address let an embedded JavaScript script query something that is only accessible by IPv4. The script can check whether this request worked or not.

… But you really should think many times is this is really what you want to do. Why not let your users use IPv6?

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