+ Reply to Thread
Results 1 to 5 of 5

Thread: php portcheck

  1. #1
    Joshua203's Avatar
    Joshua203 is offline x10 Sophmore Joshua203 is an unknown quantity at this point
    Join Date
    Dec 2007
    Posts
    194

    php portcheck

    this week i was trying to test a php portcheck script and i can t seem to get it to work, could it be php is not alowing it or am i screwing up?

  2. #2
    lhyman's Avatar
    lhyman is offline x10 Sophmore lhyman is an unknown quantity at this point
    Join Date
    Jun 2009
    Posts
    198

    Re: php portcheck

    more info please

    please use the code option and post the scrip here

    Thanks
    My Name is Larry Hyman from Montreal. I fix computers on site, see my web site for more details:

    http://hyman.sytes.net

  3. #3
    Joshua203's Avatar
    Joshua203 is offline x10 Sophmore Joshua203 is an unknown quantity at this point
    Join Date
    Dec 2007
    Posts
    194

    Re: php portcheck

    well ok here you go
    Code:
     
    
    /* Port Checking PHP Script
    Created by Jonesy44
    Released: 30 November, 2008 */
    
    echo '<title>Port Availability Checker';
    //Please leave the next line :)
    echo ', Writen by Jonesy44';
    echo '</title>';
    
    $addr = $_SERVER["REMOTE_ADDR"];
    $port = "80";
    if ($_GET["addr"]) {
    $addr = $_GET["addr"];
    }
    if ($_GET["port"]) {
    $port = $_GET["port"];
    }
    if ($_GET["port2"]) {
    $port2 = $_GET["port2"];
    }
    
    
    echo '<form action="' .$_SERVER["PHP_SELF"]. '" method="get">
    <div style="width:300px;background:#f1f1f1;padding:10px;font-family:arial;">
    <table width="100%" border="0" cellspacing="0" cellpadding="2">
    <tr>
    <td colspan="2" style="font-size:12px;">Please enter the Address/IP and port of the website or IP address you wish to test (enter the second IP if you want so scan to that port range)</td>
    </tr>
    <tr>
    <td width="30%" style="font-size:12px;">Address/IP</td>
    <td width="80%"><input type="text" name="addr" value="' .$addr. '"></td>
    </tr>
    <tr>
    <td width="30%" style="font-size:12px;">Port</td>
    <td width="80%"><input type="text" name="port" value="' .$port. '"></td>
    </tr>
    <tr>
    <td width="30%" style="font-size:12px;">-</td>
    <td width="80%"><input type="text" name="port2" value="' .$port2. '"></td>
    </tr>
    <td width="30%">&nbsp;</td>
    <td width="80%"><input type="submit" value="Check/Scan Port(s)"></td>
    </tr>
    </table>
    </div>
    </form>
    ';
    
    if ($_GET["addr"]) {
    if ($_GET["port"] && !$_GET["port2"]) {
    $fp = @fsockopen($addr, $port, $errno, $errstr, 2);
    $success = "#FF0000";
    $success_msg = "is closed and cannot be used at this time";
    if ($fp) {
    $success = "#99FF66";
    $success_msg = "is open and ready to be used";
    }
    @fclose($fp);
    echo '<div style="width:300px;background:' .$success. ';padding:10px;font-family:arial;font-size:12px;">
    The address <b>"' .$addr. ':' .$port. '"</b> ' .$success_msg. '
    </div>';
    }
    else if ($_GET["port"] && $_GET["port2"]) {
    $p1 = $_GET["port"];
    $p2 = $_GET["port2"];
    if ($p1 == $p2) {
    $fp = @fsockopen($addr, $port, $errno, $errstr, 2);
    $success = "#FF0000";
    $success_msg = "is closed and cannot be used at this time";
    if ($fp) {
    $success = "#99FF66";
    $success_msg = "is open and ready to be used";
    }
    @fclose($fp);
    echo '<div style="width:300px;background:' .$success. ';padding:10px;font-family:arial;font-size:12px;">
    The address <b>"' .$addr. ':' .$port. '"</b> ' .$success_msg. '
    </div>';
    }
    else {
    if ($p1 < $p2) {
    $s = $p1;
    $st = $p1;
    $e = $p2;
    }
    else if ($p2 < $p1) {
    $s = $p2;
    $st = $p2;
    $e = $p1;
    }
    while ($s <= $e) {
    $fp = @fsockopen($addr, $s, $errno, $errstr, 1);
    if ($fp) {
    $p_open = $p_open. " " .$s;
    $p_1 = 1;
    }
    @fclose($fp);
    $s++;
    }
    if ($p_1) {
    $c = "#99FF66";
    $m = "On the address <b>" .$addr. "</b> and port range <b>" .$st. "-" .$e. "</b> the following ports were open: " .$p_open;
    }
    else {
    $c = "#FF0000";
    $m = "No ports on the address <b>" .$addr. "</b> and port range <b>" .$st. "-" .$e. "</b> were open";
    }
    echo '<div style="width:300px;background:' .$c. ';padding:10px;font-family:arial;font-size:12px;">' .$m. '</div>';
    }
    }
    }
    this works partly on my wamp server but shows errors
    it fails horibly on the free server but no errors

    i m no big scripter or anything but maybe fsockopen is not allowed?

  4. #4
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,636

    Re: php portcheck

    The script works for me (after adding <?php tag to start )\\

    Also, try testing if a function exist and if it is working properly:

    Code:
    <html>
    <head><title>TESTING</title></head>
    <body>
    
    <?php
    
    $fun = 'fsockopen' ;
    
    // TO SEE IF THE FUNCTION EXITS
    
    if( function_exists( $fun ) ){
       echo "$fun exists";
    } else {
       echo "$fun does not exist";
    }
    
    // HARD CODE THE INFORMATION AND TEST JUST ONE FUNCTION
    
    $fp = fsockopen("www.example.com", 80, $errno, $errstr, 30);
    if (!$fp) {
        echo "$errstr ($errno)<br />\n";
    } else {
        $out = "GET / HTTP/1.1\r\n";
        $out .= "Host: www.example.com\r\n";
        $out .= "Connection: Close\r\n\r\n";
        fwrite($fp, $out);
        while (!feof($fp)) {
            echo fgets($fp, 128) . "<br \>";
        }
        fclose($fp);
    }
    ?>
    </body>
    </html>
    Nothing is always absolutely so.

  5. #5
    Joshua203's Avatar
    Joshua203 is offline x10 Sophmore Joshua203 is an unknown quantity at this point
    Join Date
    Dec 2007
    Posts
    194

    Re: php portcheck

    php tags are there sorry that was not in the example i used to copy from

    yes it may look like it works fine (like i said it shows no error)
    but from what i see the outcome cannot be right

    i must admit i wouldn t know where to start on testing a function that s why i popped the question :laugh:

    but thnx for your reply sofar ;)

    EDIT: reading better i spotted the hint lol, sorry ....and thnx i will try this
    Edit:
    probably automerged as an edit:

    the test was positive yes, hmmm i ll play around with it some more, because i still don t trust the portcheck's outcome to be correct:dunno:
    Last edited by Joshua203; 08-14-2009 at 06:29 PM. Reason: Automerged Doublepost

+ Reply to Thread

Similar Threads

  1. Ever Been Suspended For Using PHP?
    By dragoneye_xp in forum Off Topic
    Replies: 26
    Last Post: 08-16-2009, 07:17 PM
  2. [PHP] Variables in PHP
    By Bryon in forum Tutorials
    Replies: 15
    Last Post: 01-29-2009, 09:46 AM
  3. currently have an application pending php
    By biomasti in forum Free Hosting
    Replies: 1
    Last Post: 09-03-2008, 01:58 PM
  4. php errors galore
    By DMG Online in forum Scripts & 3rd Party Apps
    Replies: 9
    Last Post: 05-17-2008, 06:23 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers