I was able to figure out why some websites get IPV4 even using IPV6 at the same time and my hosting does not, the routes used may vary from the server where the PHP script was hosted, so there is really no way this can be done without using third party service.
Now an alternative solution, it is worth remembering that I will not post the third party service I used because I believe that this is poorly seen by the community, and that it can also be considered a poorly done system.
In order to solve I used this service to convert IPV4 to JSON:
http://<ipv4 ipv6 service>/json/widgetdata.php?callback=_jqjsp&_1518034744039=
It returns a JSON:
_jqjsp({"address":"179.XXX.XXX.XX5","proto":"ipv4","country_code":"BR","country":"Brazil"})
But you cannot use xmlHTTPrequest to receive values from another JSON from another hosting, so through its URL I changed the term of the variable callback so that the gambiarra causing the service PHP to create a Javascript variable using the equal sign (=) so %3D to accept URL:
http://<ipv4 ipv6 service>/json/widgetdata.php?callback=dataipv4%3D
And calling it HTML the variable is accessible to your browser as a JSON object:
var dataipv4=({"address":"177.XXX.XXX.XX5","proto":"ipv4","country_code":"BR","country":"Brazil"})
So now yes with xmlHTTPRequest it was enough to use the variable dataipv4.address to get the IP and send by GET method to a PHP that uses the IP:
function showIpv(ip) {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
console.log()
}
};
xmlhttp.open("GET", "write_ipv4.php?ip="+ip, true);
xmlhttp.send();
}
The write_ipv4.php file that is in the hosting:
<?php
if(isset($_GET['ip']) && !empty($_GET['ip'])){
/* User a variavel global $_GET['ip'] da maneira que preferir
Por exemplo:
echo $_GET['ip']
retorna o IP no formato XXX.XXX.XXX.XXX
*/
}else{
console.log('Acesso direto proibido');
}
?>
https://tools.ietf.org/html/rfc8305
– Michael Hampton