S
S
Sergey Korenevsky2018-03-11 03:49:03
PHP
Sergey Korenevsky, 2018-03-11 03:49:03

How to find out IPv4 from IPv6 in PHP within your server?

$_SERVER[REMOTE_ADDR] returns 2a03:6f00:1::5c35:6074
Would like to know IPv4 though.
Is it possible to find out in PHP by contacting the DNS server?
I want to know the external IP of the server. The fact is that the IP for accessing the server and the IP by which it accesses other servers are different.
maddog670 , Gave a great answer!!::

$content = file_get_contents('http://checkip.dyndns.com/');
preg_match('/Current IP Address: \[?([:.0-9a-fA-F]+)\]?/', $content, $ip);
$serverIP = $ip[1];

Answer the question

In order to leave comments, you need to log in

4 answer(s)
M
maddog670, 2018-03-11
@Dier_Sergio_Great

These are completely different things and you can’t recognize ipv6 from ipv4, and vice versa

A
Alexander Aksentiev, 2018-03-11
@Sanasol

Try to make an Ajax request to a site that ONLY listens on ipv4 or ipv6.
And so to find out whether the user supports ipv6 at all, and at the same time both IPs are in the process.
This is true for any services that check the presence and operation of ipv6.
Otherwise, I don't see the point at all.

S
Sanya Krotov, 2019-05-20
@kollenok

If in php then so

<?php
  echo $_SERVER["REMOTE_ADDR"];
?>

And if you need to look at your IP address from a computer, then I look through this site - https://calcok.com/kompyutery/2.php

S
Sergey Abdulov, 2019-09-24
@tonik7serik

Do you need something like this?
There, when you log in, you can see your current IP address that your provider gave you - https://calcok.com/kompyutery/2.php

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question