php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #24785 Warning: fsockopen() [function.fsockopen]: php_hostconnect: connect failed
Submitted: 2003-07-23 21:15 UTC Modified: 2003-07-24 13:12 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: laudanp at yahoo dot com Assigned:
Status: Closed Package: Sockets related
PHP Version: 4CVS-2003-07-23 (stable) OS: Redhat 7.3
Private report: No CVE-ID: None
 [2003-07-23 21:15 UTC] laudanp at yahoo dot com
Description:
------------
Please reference: http://bugs.php.net/bug.php?id=21653, as it is the same for this bug report.  I was asked to file a new one.  The CVS codebase I'm using is: php4-STABLE-200307031530.tar.gz.  The following line is where the error occurs in my script:

$handle = fsockopen($this-> targetIP, $index, $errno, $errstr, $this->
timeout);


You may see the script in action here:

http://www.computercops.biz/modules.php?name=TCP_Scanner

or

http://www.computercops.biz/modules.php?name=Trojan_TCP_Scan

I obtain that fsockopen error.

It was stated by wez in the above referenced bug report that he removed a duplicate error message.  I grabbed the latest cvs after that and it still wasn't working.

Below is the code that I include in a parent PHP script.  Its the "core" though.

Reproduce code:
---------------
<?php
# COPYRIGHT PAUL LAUDANSKI / COMPUTERCOPS.BIZ

        $trojans = array("21" => "Nerte 7.8.1",
                    "23" => "TruvaAti 1.2 beta"
        );
        flush();
        while (list ($portno, $descno) = each ($trojans)) {
                flush();
                $fp = fsockopen($REMOTE_ADDR, $portno, $errno, $errstr, 1);
                if(!$fp) {
                        echo "Connection Refused: ";
                        echo "Port $portno used by $descno.";
                        echo "<BR>";
                } else {
                        echo "<FONT COLOR=red><B>ESTABLISHED CONNECTION</b>: ";
                        echo "Possible $descno Trojan found on port $portno.</FONT>";
                        echo "<BR>";
                        $start = time();
                        socket_set_timeout($fp, 5);
                        $ccspstrNumberFound++;
                        fclose($fp);
                }
        }
?>

Expected result:
----------------
Starting Trojan TCP Scan ...
Connection Refused: Port 21 used by Nerte 7.8.1.
Connection Refused: Port 23 used by TruvaAti 1.2 beta.

etc...



Actual result:
--------------
Starting Trojan TCP Scan ...

Warning: fsockopen(): unable to connect to xxx.xxx.xxx.xxx:21 in /www/computercops/modules/Trojan_TCP_Scan/ccspTrojans.php on line 137
Connection Refused: Port 21 used by Nerte 7.8.1.

Warning: fsockopen(): unable to connect to xxx.xxx.xxx.xxx:23 in /www/computercops/modules/Trojan_TCP_Scan/ccspTrojans.php on line 137
Connection Refused: Port 23 used by TruvaAti 1.2 beta.

etc...

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-07-24 03:45 UTC] wez@php.net
Sounds like expected behaviour to me.
Why is this wrong?
If you want to suppress the warning messages generated by PHP, you can use the @ operator.
 [2003-07-24 12:57 UTC] laudanp at yahoo dot com
Good point.  Prior to 4.3.x there was no need for "@" as the error didn't show.  After it, but prior to the CVS "fix", using "@" didn't seem to matter.  The error showed itself. 

I just added the "@" to the fsockopen line and the Trojan scan works without the error.

Amazing.  So it's now resolved.
 [2003-07-24 13:10 UTC] iliaa@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

User indicated that expected behaviour is what's happening in the test script, not a bug.
 [2003-07-24 13:12 UTC] laudanp at yahoo dot com
I'd say this is not "bogus" as this is a "closed" issue.  See this ticket:

http://bugs.php.net/bug.php?id=21653

You'll notice that up to a certain CVS build version of PHP, the bug is *very real*.  Wez had to modify PHP in order for the bug to be removed.

Hence, if a website isn't using the latest CVS, then the bug is very real.

Solution: get the latest CVS snapshot.  This is not bogus and shouldn't be labelled as such.  Please see the reference bug report above for proof.
 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Wed Jan 26 00:03:34 2022 UTC