php icon indicating copy to clipboard operation
php copied to clipboard

Retrieving your public IPv6 address

Open Eddict opened this issue 2 years ago • 1 comments

I am trying to retrieve my public IPv6 address but the getDetails() function, with $ip_address paramater set to null, only returns the IPv4 address. i have tried changing the const API_URL of the IPinfo class to 'https://v6.ipinfo.io' but somehow that leads to an curl error 7 which i do not understand. because if i use curl directly it works.

curl ipinfo.io/?token=mytoken

returns json with ip as ipv4 address

curl ipinfo.io/ip/?token=mytoken

returns string ip as ipv4 address

curl v6.ipinfo.io/ip/?token=mytoken

returns string ip as ipv6 address

curl https://v6.ipinfo.io/ip/?token=mytoken

returns string ip as ipv6 address

any idea why the curl error?

Eddict avatar Mar 12 '23 21:03 Eddict

I know that this is an old issue, and perhaps is resolved. If not I could give the following suggestion:

  1. Verify that you run the curl from the command line from the same machine that you run the php code from.
  2. Verify PHP cURL IPv6 Support Check if your PHP cURL installation supports IPv6:
<?php
$curl_version = curl_version();
echo "cURL Version: " . $curl_version['version'] . "\n";
echo "Features: " . $curl_version['features'] . "\n";
echo "IPv6 Support: " . ($curl_version['features'] & CURL_VERSION_IPV6 ? "Yes" : "No") . "\n";
?>
  1. Test Direct cURL Request in PHP
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://v6.ipinfo.io/ip?token=your_token_here");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V6); // Force IPv6
$result = curl_exec($ch);
if ($result === false) {
    echo "cURL Error: " . curl_error($ch) . " (Code: " . curl_errno($ch) . ")\n";
} else {
    echo "Result: " . $result . "\n";
}
curl_close($ch);
?>

rvalitov avatar Apr 25 '25 12:04 rvalitov