Using fsockopen() with IPv6

  • wpas
  • Proficient
  • Proficient
  • User avatar
  • Posts: 378
  • Loc: Canada

Post 3+ Months Ago

I have the following ipv6 address:

2001:4998:58:c02::a9

Now using the command prompt in my windows 8 I ping it and get:

Microsoft Windows [Version 6.3.9600]
(c) 2013 Microsoft Corporation. All rights reserved.

C:\WINDOWS\system32>ping 2001:4998:58:c02::a9

Pinging 2001:4998:58:c02::a9 with 32 bytes of data:
Reply from 2001:4998:58:c02::a9: time=40ms
Reply from 2001:4998:58:c02::a9: time=64ms
Reply from 2001:4998:58:c02::a9: time=62ms
Reply from 2001:4998:58:c02::a9: time=42ms

Ping statistics for 2001:4998:58:c02::a9:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 40ms, Maximum = 64ms, Average = 52ms


Now I try to connect using the fsockopen()

$fp = fsockopen('[2001:4998:58:c02::a9]', 80);

I put [ ] around ipv6 as mentioned in the PHP manual

When I run I get the following:

Could not connect to [2001:4998:58:c02::a9]
The error message was 101: Network is unreachable

Am I doing something wrong?
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9193
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

What version of PHP are you utilizing?

Also if you run phpinfo() and look at the results, does it show IPV6 is enabled?
  • wpas
  • Proficient
  • Proficient
  • User avatar
  • Posts: 378
  • Loc: Canada

Post 3+ Months Ago

As a test, I ran the local host in ipv6:

[::1]

This worked with fsockopen()

Then I decided to try an ipv4 from yahoo.com and mapped to ipv6:

98.139.180.149 ===> [::ffff:628b:b495]

This worked with fsockopen

Just for the hell of it use [::] and it worked with fsockeopen

Finally ran phpinfo() it ipv6 was enabled
  • wpas
  • Proficient
  • Proficient
  • User avatar
  • Posts: 378
  • Loc: Canada

Post 3+ Months Ago

This ipv6 is really starting to baffle me.

Someone told me connection depends more on your browser not your PHP configuration

I used my browser to access

http://[2001:41d0:2:381::14]/

and it worked.

I then tried with fsockopen() and got Network Unreachable

There has to be something I am missing?

Anyone else have similar problems
  • wpas
  • Proficient
  • Proficient
  • User avatar
  • Posts: 378
  • Loc: Canada

Post 3+ Months Ago

Is there not anybody out there who has some understanding of IPv6 address?
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8489
  • Loc: USA

Post 3+ Months Ago

Well, I don't know much about IPv6 but some Google searching yielded some similar problems that you have and insight to them. I'm sure you have already searched and tried many things, but I've decided to try and help the best I could :D

I've meant to try and mess around with IPv6 but haven't gotten the time for it (or many things) so maybe this would help me get started on messing around with them as well :)

http://stackoverflow.com/questions/3097 ... -fsockopen

http://www.fix6.net/archives/2009/04/24/php-and-ipv6/


Maybe these would help some:

https://bugs.php.net/bug.php?id=30057
https://bugs.php.net/bug.php?id=40279
  • wpas
  • Proficient
  • Proficient
  • User avatar
  • Posts: 378
  • Loc: Canada

Post 3+ Months Ago

Here is my situation so far.

I have the following ipv6 address:
2001:41d0:2:381::14

In my browser I put in the url:
http://[2001:41d0:2:381::14]/

I am able to connect to the website.

Now I try to connect from my website using fsockopen

Code: [ Select ]
<?php
$domaine = "[2001:41d0:2:381::14]";
//Try To Establish a communication connection before attempting to get webpage data
echo "Trying To Connect To $domaine";
$hostp = $domaine;
function ping($hostp,$port=80, $timeout=3)
{
  if (!$file = fsockopen($hostp,$port,$errno,$errstr,$timeout))
  {
   echo "Could not connect to $hostp <br />The error message was $errno: $errstr<br />The Website is either Down or does not exist<br /><br />";
   fclose($file);
  }
  else
  {
  $x = 0;
  while($x<2)
  {
    $starttime = microtime(true);
    $file = @fsockopen($hostp,$port,$errno,$errstr,$timeout);
    fclose($file);
    $stoptime = microtime(true);
    $ping = ($stoptime - $starttime) * 1000;
    $ping = floor($ping);
    //echo "Connected to [ $host ] in $ping ms.<br />"; 
    //$ping += $ping;
    $x++;
    if($x == 2)
       {
      $output = "Connection to $hostp established in $ping ms<br /><br />";
       }
    }
    }
  
  return $output;
}

echo ping($hostp);

?>
  1. <?php
  2. $domaine = "[2001:41d0:2:381::14]";
  3. //Try To Establish a communication connection before attempting to get webpage data
  4. echo "Trying To Connect To $domaine";
  5. $hostp = $domaine;
  6. function ping($hostp,$port=80, $timeout=3)
  7. {
  8.   if (!$file = fsockopen($hostp,$port,$errno,$errstr,$timeout))
  9.   {
  10.    echo "Could not connect to $hostp <br />The error message was $errno: $errstr<br />The Website is either Down or does not exist<br /><br />";
  11.    fclose($file);
  12.   }
  13.   else
  14.   {
  15.   $x = 0;
  16.   while($x<2)
  17.   {
  18.     $starttime = microtime(true);
  19.     $file = @fsockopen($hostp,$port,$errno,$errstr,$timeout);
  20.     fclose($file);
  21.     $stoptime = microtime(true);
  22.     $ping = ($stoptime - $starttime) * 1000;
  23.     $ping = floor($ping);
  24.     //echo "Connected to [ $host ] in $ping ms.<br />"; 
  25.     //$ping += $ping;
  26.     $x++;
  27.     if($x == 2)
  28.        {
  29.       $output = "Connection to $hostp established in $ping ms<br /><br />";
  30.        }
  31.     }
  32.     }
  33.   
  34.   return $output;
  35. }
  36. echo ping($hostp);
  37. ?>


This did not connect.
Error was "Network is unreachable".

I then checked my PHP on my website using php():
It stated ipv6 was enabled.

As a test, I ran the local host in ipv6:
[::1]
This worked with fsockopen()

Then I decided to try an ipv4 from yahoo.com and mapped to ipv6:
98.139.180.149 ===> [::ffff:628b:b495]
This worked with fsockopen

Just for the hell of it I used [::] and it worked with fsockeopen

I spoke with my hosting company and they told me I did not have an ipv6 address only an ipv4
This is where I am confused now.

If I use my browser to connect to the internet through my ISP, I know I have an ipv6 address and can connect to ipv6 sites.
When I use the fsockopen script on my website, I cannot make any real ipv6 connections.
Is this because my website does not have an ipv6 address even though my php says ipv6 es enable.
But as I stated before, I was able to fsockopen() to [::1], [::] and mapped ipv6 [::ffff:628b:b495].

Can someone help me here?
  • wpas
  • Proficient
  • Proficient
  • User avatar
  • Posts: 378
  • Loc: Canada

Post 3+ Months Ago

I added my IPv4 address mapped to IPv6 to my DNS records
When I did a DNS record check it actually showed my mapped IPv6 as an AAAA record for IPv6.

I even used my browser, worked only with Chrome, to connect to website using url http://[::ffff:628b:b495]/ and it worked.
However, my website indicated that I was using IPv4 and actually showed my IPv4 address.

I think it all boils down to my hosting company not giving me IPv6.
This means I am stuck as an IPv4 only address.

I have been reading a lot about tunnelling, gateways etc. to connect IPv4 to IPv6.

What I need to do then is reach IPv6 addresses from an IPv4-only network.

Sometimes I only know the IPv6 address of the website not the domain name so I need to be able to check if there is a connection using IP address only.

Can someone give me some ideas on how I could do this.
This appears to be the only way I will be able to connect to IPv6 websites from my IPv4 website.
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9193
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

Unfortunately I myself don't know enough about IPv6 to be able to help you. I suspect you might be right though with your web host needing to provide you an IPv6 address or block of addresses for you to make this work though.

With that said, as far as I am aware the majority of hosts fall back to IPv4, I have not seen any websites that are IPv6 only as if they were they would likely have numerous clients not being able to connect.

Do you have an example of a website that you are trying to connect to that is really only IPv6?
  • wpas
  • Proficient
  • Proficient
  • User avatar
  • Posts: 378
  • Loc: Canada

Post 3+ Months Ago

The IP below is an IPv6 site

http://[2001:41d0:2:381::14]/

If you have IPv6 browser and click on link, it will take you to the IPv6 sit
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9193
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

Yeah but that website also has an IPv4 IP address to fall back on for people who don't have IPv6:

http://87.98.225.184/
  • KarenButler
  • Born
  • Born
  • KarenButler
  • Posts: 1

Post 3+ Months Ago

I look at these messages and understand that I don't understand anything))) Frankly speaking, I need some lessons from IP and URL... :cry:

Post Information

  • Total Posts in this topic: 12 posts
  • Users browsing this forum: No registered users and 25 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2017. Ozzu® is a registered trademark of Unmelted, LLC.