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

Thread: PHP Port Scanner

  1. #1
    TkTech's Avatar
    TkTech is offline The Crazy One
    Join Date
    Jun 2006
    Location
    Canada
    Posts
    1,412
    Blog Entries
    1
    Rep Power
    31

    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 Attached Files

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Location
    Advertising world
    Posts
    Many

     
  3. #2
    Join Date
    Jul 2006
    Location
    Amherst, New York, United States
    Posts
    6,277
    Blog Entries
    26
    Rep Power
    20

    Re: PHP Port Scanner

    Well, mine was just a tutorial.

  4. #3
    Jordan Guest

    Re: PHP Port Scanner

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

  5. #4
    Join Date
    Jan 2008
    Posts
    1,725
    Blog Entries
    4
    Rep Power
    29

    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 :/

  6. #5
    TkTech's Avatar
    TkTech is offline The Crazy One
    Join Date
    Jun 2006
    Location
    Canada
    Posts
    1,412
    Blog Entries
    1
    Rep Power
    31

    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

  7. #6
    Jordan Guest

    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.

  8. #7
    Join Date
    May 2008
    Posts
    2,126
    Blog Entries
    1
    Rep Power
    33

    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'.

  9. #8
    Jordan Guest

    Re: PHP Port Scanner

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

  10. #9
    Join Date
    Jan 2008
    Posts
    1,725
    Blog Entries
    4
    Rep Power
    29

    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.

  11. #10
    geniushasan is offline Newbie
    Join Date
    Oct 2008
    Posts
    1
    Rep Power
    0

    Re: PHP Port Scanner

    thanks

+ Reply to Thread
Page 1 of 5 123 ... LastLast

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [Java] Port Scanner
    By Impulser in forum Classes and Code Snippets
    Replies: 0
    Last Post: 01-13-2010, 01:30 PM
  2. Ruby Port Scanner
    By JMC31337 in forum Classes and Code Snippets
    Replies: 6
    Last Post: 04-07-2009, 06:58 AM
  3. Specific port Scanner
    By Slashgate in forum Visual Basic Programming
    Replies: 4
    Last Post: 04-02-2009, 08:30 AM
  4. Simple Port Scanner in PHP
    By robertiptv in forum Classes and Code Snippets
    Replies: 4
    Last Post: 01-09-2009, 12:23 PM

Tags for this Thread

Bookmarks

Posting Permissions

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