I have a script using fsockopen() which fails.

Warning: fsockopen(): unable to connect to ...:7 in /home/virtual/site20/fst/home/cipher/public_html/test.php on line 11
port 7 closed on ...

I have tried two similar scripts both using fsockopen() and neither work failing on fsockopen()

Any ideas?

Thanks ... Fizz

    Could we have some code please?
    Are you catching errno and errstr?
    Bubble

      errno is 110 errstr is Connection timed out

      $ptcp = fsockopen($ip, $port, &$errno, &$errstr, 30);
       if($ptcp) {$status=1;} /* return 1 for open port (so users can display their own message */
                else {$status=0;}      /* return 0 for closed port (so users can display their own message */
      

      where ip is in the format ...
      port is typically something like 80

        if(!($ptcp = fsockopen($ip, $port, &$errno, &$errstr)) {
           $status=0;
        } else {
           socket_set_timeout($ptcp,30);
           $status=1;
           fclose ($ptcp);
        }
        

          Hi TTT
          Although your code is a little neater it does the same thing and also fails.

          I suspect that this may be an issue other than purely code. Are there any other conditions that can prevent this function from working?

            Do you know for sure that a socket can be opened? Have you been able to do it successfully from the console?
            Bubble

              Hi bubblenut.

              I'm not sure what you mean. What can I do to ensure a soket can be opened from the console?

                Ah, in that case there are no problems opening sockets from console.

                The script is a simple port scanning utility so a browser can see what open ports he/she has. I didnt write the script but I have altered it so that it scans the browser's ip

                I have tried two seperate scripts which do much the same thing but both fail with the "fsockopen(): unable to connect to " error.

                Given that these are established scripts I wondered if something needed enabling to allow this function to work.

                  Write a Reply...