+ Reply to Thread
Page 1 of 5
1 2 3 ... LastLast
Results 1 to 10 of 42

Thread: PHP Port Scanner

  1. #1
    The Crazy One TkTech will become famous soon enough TkTech's Avatar
    Join Date
    Jun 2006
    Location
    Canada
    Age
    18
    Posts
    1,549
    Blog Entries
    1

    PHP Port Scanner

    In an attempt to one-up John ( ) I made this little PHP Port scanner.
    You can host it on your site or standalone, and it will work from both the command line and the web (Although the web interface is a lot prettier.)
    The way it is right now, it just checks the IP of whoever loads the page.

    Currently includes port types and definitions for roughly 48000 ports.

    Class.IOType.php
    Code:
    <?php
    if(!defined("__IOType")) die("-_-");
    class 
    IOType
    {
        public 
    $GUESS false;
        public 
    $PORTS;
        
        function 
    Assign($ports){
            
    $this->PORTS $ports;
        }
        function 
    Check($hostname,$port 80){
            
    $fp = @fsockopen($hostname$port$errno$errstr1);
            
    $ret["hostname"] = $hostname;
            
    $ret["port"]     = $port;
            
    $ret["guess"]    = $this->GUESS;
            
    $ret["default"] = $this->PORTS[$port];
            
            if(
    $fp){
                
    $ret["type"]    = "OPEN";
                if(!
    $this->GUESS){
                    
    $ret["truetype"]= $this->ident($fp);
                    return 
    $ret;
                }else{
                    return 
    $this->ident($fp);
                }
            }else{
                
    $ret["type"]    = "CLOSED";
                return 
    $ret;
            }
                
        }

        function 
    lookup($port){
            return 
    $fake;    
        }

        function 
    ident($fp){
            
    stream_set_timeout($fp,2);
        
    //    $raw = fread($fp,3);
            
    fclose($fp);
            switch(
    $raw){
                case 
    "SSH":
                    return 
    "SSH";
                case 
    "+OK":
                    return 
    "POP3";
            }
        }
    }
    ?>
    Example.php
    Code:
    <?php
    define
    ("__IOType",TRUE);
    global 
    $LibIOType;
    global 
    $MyIOType;
    global 
    $MyHost;

    $MyHost = (!$_SERVER['SERVER_ADDR']) ? "127.0.0.1" 
    getenv(REMOTE_ADDR);

    include_once(
    "Class.IOType.php");
    include_once(
    "Library.IOType.php");

    $MyIOType = new IOType;
    $MyIOType->Assign($LibIOType);

    if(empty(
    $_SERVER['SERVER_ADDR'])){
        include_once(
    "CLI.IOType.php");
    }else{
        include_once(
    "WEB.IOType.php");
    }

    ?>
    WEB.IOType.php
    Code:
    <?php
    echo
    "<HTML>\n
    <head>\n
    <title>TK Port Scan@Codecall.net</title>\n
    <link rel=\"stylesheet\" type=\"text/css\" href=\"ports.css\" />
    <SCRIPT TYPE=\"text/javascript\" LANGUAGE=\"javascript\">
    function waitPreloadPage() { //DOM
    if (document.getElementById){
    document.getElementById('prepage').style.visibility='hidden';
    }else{
    if (document.layers){ //NS4
    document.prepage.visibility = 'hidden';
    }
    else { //IE4
    document.all.prepage.style.visibility = 'hidden';
    }
    }
    }
    </SCRIPT>
    </head>\n
    <body onLoad=\"waitPreloadPage();\">\n
    <DIV id=\"prepage\" style=\"position:absolute; font-family:arial; font-size:16; left:0px; top:0px; 
    background-color:white; layer-background-color:white; height:100%; width:100%;\"> 
    <TABLE width=100%><TR><TD><B>Loading ... ...</B></TD></TR></TABLE>
    </DIV>
    <center><a href=\"Example.php?type=all\">All Ports</a> | <a href=\"Example.php?type=open\">Open Ports</a> | <a 
    href=\"Example.php?type=sec\">Summary</a></center>
    <table class=\"servicesT\" cellspacing=\"0\">\n
    <tr><td colspan=\"3\" class=\"servHd\">Port Scan Results</td></tr>\n
    "
    ;
    for(
    $i=20;$i<=4000;$i++){
        
    $result $MyIOType->Check($MyHost,$i);
        if(!(
    $result["type"] == "CLOSED" && $_GET["type"] == "open")){
            if(
    $result["type"] == "OPEN")
                
    $color "color: #FF0000;";
            else
                
    $color "color: #3EA99F;";

            echo 
    "<tr>
                <td>$i</td>
                <td class=\"servBodL\"><b>{$result["default"]["type"]}</b></td>
                <td class=\"servBodL\" style=\"$color\" width=\"10%\"><b>{$result["type"]}</b></td></tr>"
    ;
            if(!empty(
    $result["default"]["desc"])){
            echo 
    "
            <tr>
                <td></td>
                <td colspan=\"3\"><i>{$result["default"]["desc"]}</i></td>
            </tr>
            "
    ;
            }
        }
    }
    echo     
    "
    <tr><td colspan=\"3\" class=\"servHd\"><- Comming soon to a theater near you! -></td></tr>\n
    </table>"
    ;
    ?>
    ports.css
    Code:
    table.servicesT
    font-familyVerdana;
    font-weightnormal;
    font-size11px;
    color#404040;
    width100%;
    background-color#fafafa;
    border1px #6699CC solid;
    border-collapsecollapse;
    border-spacing0px;
    margin-top0px;}


    table.servicesT td.servHd
    border-bottom2px solid #6699CC;
    background-color#BEC8D1;
    text-aligncenter;
    font-familyVerdana;
    font-weightbold;
    font-size11px;
    color#404040;}


    table.servicesT td
    border-bottom1px dotted #6699CC;
    font-familyVerdanasans-serifArial;
    font-weightnormal;
    font-size11px;
    color#404040;
    background-colorwhite;
    text-alignleft;
    padding-left3px;}

    .
    servBodL border-left1px dotted #CEDCEA; } 
    .open {
    color#FF0000;
    }
    .
    closed {
    color#3EA99F;

    CLI.IOType.php
    Code:
    <?php
    for($i=20;$i<=111;$i++){
        
    $result $MyIOType->Check($MyHost,$i);
        echo 
    $i "::" $result["port"] . "[" $result["default"]["type"] . "]        " $result["type"] . "    " $result["truetype"] . "\n";
    }
    ?>
    Library.IOType.php
    Download
    Attached Files

  2. #2
    Co-Administrator John is a glorious beacon of light John is a glorious beacon of light John is a glorious beacon of light John is a glorious beacon of light John is a glorious beacon of light John's Avatar
    Join Date
    Jul 2006
    Age
    21
    Posts
    5,885
    Blog Entries
    25

    Re: PHP Port Scanner

    Well, mine was just a tutorial.

  3. #3
    Administrator Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan's Avatar
    Join Date
    Nov 2005
    Location
    Hendersonville, NC
    Posts
    24,556
    Blog Entries
    97

    Re: PHP Port Scanner

    Why not attach all of the files as one zip file?

  4. #4
    Guru morefood2001 is just really nice morefood2001 is just really nice morefood2001 is just really nice morefood2001 is just really nice
    Join Date
    Jan 2008
    Posts
    1,724
    Blog Entries
    4

    Re: PHP Port Scanner

    Nice code It would be nice if I didn't have to use my cell phone to scan ports lol.

    Our University firewall blocks these types of programs :/

  5. #5
    The Crazy One TkTech will become famous soon enough TkTech's Avatar
    Join Date
    Jun 2006
    Location
    Canada
    Age
    18
    Posts
    1,549
    Blog Entries
    1

    Re: PHP Port Scanner

    Quote Originally Posted by Jordan View Post
    Why not attach all of the files as one zip file?
    Because I'll be editing them quite often and I'm a lazy bum

  6. #6
    Administrator Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan's Avatar
    Join Date
    Nov 2005
    Location
    Hendersonville, NC
    Posts
    24,556
    Blog Entries
    97

    Re: PHP Port Scanner

    Quote Originally Posted by TkTech View Post
    Because I'll be editing them quite often and I'm a lazy bum
    LOL, fair enough.

  7. #7
    MeTh0Dz is a name known to all MeTh0Dz is a name known to all MeTh0Dz is a name known to all MeTh0Dz is a name known to all MeTh0Dz is a name known to all MeTh0Dz is a name known to all
    Join Date
    May 2008
    Posts
    476

    Re: PHP Port Scanner

    Quote Originally Posted by morefood2001 View Post
    Nice code It would be nice if I didn't have to use my cell phone to scan ports lol.

    Our University firewall blocks these types of programs :/
    There is a multitude of ways around a firewall. Especially from the 'inside'.

  8. #8
    Administrator Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan's Avatar
    Join Date
    Nov 2005
    Location
    Hendersonville, NC
    Posts
    24,556
    Blog Entries
    97

    Re: PHP Port Scanner

    SSH Tunneling being my favorite. If SSH is blocked, setup an SSH server on an unblocked port such as 80.

  9. #9
    Guru morefood2001 is just really nice morefood2001 is just really nice morefood2001 is just really nice morefood2001 is just really nice
    Join Date
    Jan 2008
    Posts
    1,724
    Blog Entries
    4

    Re: PHP Port Scanner

    I use ssh occasionally to tunnel, but since my cell connection can stay on 24x7, so I just prefer to use that (its a simple button click to access it) lol.

    I guess my point is, if you think a port should show up but doesn't, check your firewall.

  10. #10
    Newbie geniushasan is an unknown quantity at this point
    Join Date
    Oct 2008
    Posts
    1

    Re: PHP Port Scanner

    thanks

+ Reply to Thread
Page 1 of 5
1 2 3 ... LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. VB 6.0: Tutorial, Making a Port Scanner
    By TcM in forum VB Tutorials
    Replies: 119
    Last Post: 08-24-2009, 02:59 PM
  2. Simple TCP port scanner for beginners
    By billy786 in forum C and C++
    Replies: 2
    Last Post: 06-20-2008, 11:32 AM

Bookmarks

Bookmarks

     
        Algorithms and Data Structures

        Java tutorials

        Algorithms Forum

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts