server monitoring
+ Reply to Thread
Results 1 to 7 of 7

Thread: Need Help with a Port Scanner

  1. #1
    Join Date
    Sep 2006
    Posts
    1,649

    Need Help with a Port Scanner

    Okay well, I managed to make a portscanner that can take one port and scan a host to see if it is open or not. I tried to expand it so that the user could put in a range of ports to scan, but it doesn't work. Here is my code:
    [PHP]<?php

    /* PHP Port Scanner */
    /* Coded by Moonbat */
    /* May 5, 2008 */

    if (isset($_POST['portdatauno'])) {
    for ($i = $portdatauno; $i <= $portdatados; $i++) {
    $portdatauno = $_POST['portdatauno'];
    $portdatados = $_POST['portdatados'];
    $hostdata = $_POST['hostdata'];
    $scan = @fsockopen("$hostdata", $i, $errno, $errstr, *00000000000000000000000);
    if($scan) {
    echo "Port " . $i . " is <font color=\"green\"><b>OPEN</b></font> on " . $hostdata . "!";
    echo "<br>";
    } else {
    echo "Port " . $i . " is <font color=\"red\"><b>CLOSED</b></font> on " . $hostdata . "!";
    echo "<br>";
    }
    }
    flush();
    } else {

    echo <<< HTMLONE
    <html>
    <head>
    <title>PHP Port Scanner - Coded By Moonbat</title>
    <style type="text/css">
    body
    {
    background-color : #000000
    }
    h*
    {
    color : #CCCC00;
    text-align: center;
    }
    p
    {
    color : #CCCC00;
    text-align : center;
    }
    textarea
    {
    background-color : #CCCC00;
    text : #000000;
    }
    input
    {
    background-color : #CCCC00;
    }
    </style>
    </head>
    <body>
    <font face = "Verdana"><h*>PHP Port Scanner</h*></font>
    <center<font color = "CCCC00"><h*>Coded By Moonbat</h*></font></center>
    <form action = "$PHP_SELF" method = "POST" name = "PortScanData"
    <br>
    <p><b>HOSTNAME</b> (ex: google.com) </p>
    <center><input type = "text" name = "hostdata" /></center
    <p><b>PORT NUMBER RANGE</b> (ex. To scan *-20, put * in first box, and 20 in second box)
    <center><input type = "text" maxlength = "4" size = "4" name = "portdatauno" /></center>
    <p>TO</p>
    <center><input type = "text" maxlength = "4" size = "4" name = "portdatados" /></center>
    <br><br>
    <center><input type = "Submit" value = "Initiate Port Scan" /></center>
    </form>
    </body>
    </html>
    HTMLONE;
    }
    ?>[/PHP]
    It states that all ports are closed. I've tried tons of differnt ways of doing this. But even when scanning obviously open ports like port 80 on google.com I get closed. I've been using WAMP to test this, and I know that my code should be right because it works with single ports. But the minute I try to use a loop to scan a certain range, it messes up and doesn't work at all.

    Can anyone help me?
    "Workers of the world unite; you have nothing to lose but your chains." -Karl Marx

  2. #2
    Join Date
    Jan 2005
    Posts
    623
    Here is a working port scanner I wrote today. You run it through the command line:

    [php]
    <?php

    if(isset($argv['*']) && isset($argv['2']) && ctype_digit($argv['*']) && ctype_digit($argv['2']) && $argv['*']<$argv['2'] && $argv['*']>=* && $argv['2']<=655*5){

    $current_port=$argv['*'];
    $last_port=$argv['2'];

    while($current_port<=$last_port){

    $fp = @fsockopen("tcp://20*.6*.*44.*7", $current_port, $errno, $errstr,*);
    if (!$fp) {
    echo "Port: " . $current_port . " CLOSED\n";
    } else {
    echo "Port: " . $current_port . " OPEN\n";
    }
    $current_port++;
    }
    }

    ?>
    [/php]

    A few changes I made from yours to mine include using the protocals before the IP Addresses: tcp:// and the IP ADDRESS to scan for tcp port ranges. I also set timeouts to * second replacing your time of **70*7***8*764 centuries. I believe mine is more feasible :-)

    Command Line Run Command:
    Code:
    php file.php port_starting port_ending
    Example:
    Code:
    php file.php 70 *0
    This would check for all open tcp ports in the range of 70-*0
    Last edited by SyntaXmasteR; 05-12-2008 at 01:19 PM.
    [url=http://www.syntax******.info/tools/services.php]Speed Up Windows XP[/url]
    [url=http://www.syntax******.info/tools/ip.php]Get An Ip Address[/url]
    [url=http://www.syntax******.info/tools/base_converter.php]Base Converter[/url]
    --------------------------------
    [URL=http://www.boninroad.com/syntax******/]Old Site[/URL]
    [URL=http://www.syntax******.info]Comming Soon[/URL]

  3. #3
    Join Date
    Sep 2006
    Posts
    1,649
    I tried your port scanner (replace my loop with your while loop) but it still didn't work

    Any ideas why my port scanner goes koo-koo every time I try to loop it?
    "Workers of the world unite; you have nothing to lose but your chains." -Karl Marx

  4. #4
    Join Date
    Jan 2005
    Posts
    623
    Post your updated code
    [url=http://www.syntax******.info/tools/services.php]Speed Up Windows XP[/url]
    [url=http://www.syntax******.info/tools/ip.php]Get An Ip Address[/url]
    [url=http://www.syntax******.info/tools/base_converter.php]Base Converter[/url]
    --------------------------------
    [URL=http://www.boninroad.com/syntax******/]Old Site[/URL]
    [URL=http://www.syntax******.info]Comming Soon[/URL]

  5. #5
    Join Date
    Sep 2006
    Posts
    1,649
    [PHP]<?php

    /* PHP Port Scanner */
    /* Coded by Moonbat */
    /* May 5, 2008 */

    if (isset($_POST['portdatauno'])) {

    $portdatauno = $_POST['portdatauno'];
    $portdatados = $_POST['portdatados'];
    $hostdata = $_POST['hostdata'];
    while($portdatauno<=$portdatados){

    $fp = @fsockopen("$hostdata", $portdatauno, $errno, $errstr,*);
    if (!$fp) {
    echo "Port: " . $current_port . " CLOSED\n";
    } else {
    echo "Port: " . $current_port . " OPEN\n";
    }
    $portdatauno++; }

    flush();
    } else {[/PHP]
    I took out the stuff after the else because it's just using a heredoc to show some CSS and HTML.
    "Workers of the world unite; you have nothing to lose but your chains." -Karl Marx

  6. #6
    Join Date
    Jan 2005
    Posts
    623
    Well I notice a few things that may be causing problems now, but will cause problems later on:

    *. $current_port does not exist but you try to echo it
    2. You check to see if isset($_POST['portdatauno']) but then use two other post variables without checking to see if they are set.
    *. You do not define tcp:// udp:// for the ports

    Try fixing those possible issues and things should fall into place.
    [url=http://www.syntax******.info/tools/services.php]Speed Up Windows XP[/url]
    [url=http://www.syntax******.info/tools/ip.php]Get An Ip Address[/url]
    [url=http://www.syntax******.info/tools/base_converter.php]Base Converter[/url]
    --------------------------------
    [URL=http://www.boninroad.com/syntax******/]Old Site[/URL]
    [URL=http://www.syntax******.info]Comming Soon[/URL]

  7. #7
    Join Date
    Sep 2006
    Posts
    1,649
    Quote Originally Posted by SyntaX****** View Post
    Well I notice a few things that may be causing problems now, but will cause problems later on:

    *. $current_port does not exist but you try to echo it
    2. You check to see if isset($_POST['portdatauno']) but then use two other post variables without checking to see if they are set.
    *. You do not define tcp:// udp:// for the ports

    Try fixing those possible issues and things should fall into place.
    I'll make those changes and see how it goes.
    "Workers of the world unite; you have nothing to lose but your chains." -Karl Marx

+ Reply to Thread

Similar Threads

  1. IP Scanner with prorat *.*
    By dragonfly89 in forum Viruses and Trojans
    Replies: 2
    Last Post: 03-29-2008, 08:29 AM
  2. IP / Port / Lan Scanner
    By Noodles in forum Programming
    Replies: 3
    Last Post: 11-13-2007, 06:17 PM
  3. Need a port scanner in Batch
    By Raz3r in forum Internet Privacy
    Replies: 3
    Last Post: 12-05-2005, 11:54 AM
  4. port 80 and port 8080
    By ted1546 in forum Proxies and Firewalls
    Replies: 1
    Last Post: 04-17-2005, 10:22 PM
  5. Proxy Scanner
    By Virs in forum Proxies and Firewalls
    Replies: 19
    Last Post: 02-27-2003, 09:36 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