Php implements online port scan instance code

Source: Internet
Author: User

  1. <? Php
    $ Youip = $ HTTP_SERVER_VARS ["REMOTE_ADDR"];
    $ Remoteip = $ HTTP_POST_VARS [remoteip];
    ?>
  2. <Html>
  3. <Head>
  4. <Title> online port Detection Using php </title>
  5. <Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
  6. <Style TYPE = "text/css">
  7. <! --
  8. BODY {FONT-SIZE: 12px; FONT-FAMILY: Verdana; color: #000000;
  9. }
  10. TD {
  11. FONT-SIZE: 12px;
  12. FONT-FAMILY: Verdana;
  13. Color: #000000;
  14. Line-height: 14px;
  15. }
  16. . Style1 {color: # FFFFFF}
  17. -->
  18. </Style>
  19. </Head>
  20. <Body>
  21. <Center>
  22. <? Php
    If (! Empty ($ remoteip )){
    Function err (){
    Die ("sorry, this IP address is illegal <p> <a href = javascript: history. back (1)> click here to return </a> ");
    }
    // Defines the prompt message for an incorrect IP address submission.
    $ Ips = explode (".", $ remoteip );
    // Use. To separate IP addresses
    If (intval ($ ips [0]) <1 or intval ($ ips [0])> 255 or intval ($ ips [3]) <1 or intval ($ ips [3]> 255) err ();
    // If the number of the first and last IP segments is smaller than 1 or greater than 255, an error is returned.
    If (intval ($ ips [1]) <0 or intval ($ ips [1])> 255 or intval ($ ips [2]) <0 or intval ($ ips [2]> 255) err ();
    // If the number of the second and third IP addresses is less than 0 or greater than 255, an error is returned.
    $ Closed = this port is currently closed .;
    $ Opened = <font color = red> This port is currently open! </Font>;
    $ Close = "close ";
    $ Open = "<font color = red> open </font> ";
    $ Port = array (80,110,135,137,138,139,143,443,445,143, 3389 );
    $ Msg = array (Ftp, Telnet, Smtp, Finger, Http, Pop3, Location Service, Netbios-NS, Netbios-DGM, Netbios-SSN, IMAP, Https, Microsoft-DS, MSSQL, MYSQL, Terminal Services );
    // After checking the IP Format, use an array to define the service name and status of each port.
    Echo "<table border = 0 cellpadding = 15 cellspacing = 0> ";
    Echo "<tr> ";
    Echo "<td align = center> <strong> IP address you scanned: <font color = red> ". $ remoteip. "</font> </strong> </td> ";
    Echo "</tr> ";
    Echo "</table> ";
    Echo "<table cellpadding = 5 cellspacing = 1 bgcolor = #636194> ";
    Echo "<tr bgcolor = #7371A5 align = center> ";
    Echo "<td> <span class = style1> port </span> </td> ";
    Echo "<td> <span class = style1> service </span> </td> ";
    Echo "<td> <span class = style1> detection result </span> </td> ";
    Echo "<td> <span class = style1> description </span> </td> ";
    Echo "</tr> ";
    // Output the displayed table
    For ($ I = 0; $ I <sizeof ($ port); $ I)
    {
    $ Fp = @ fsockopen ($ remoteip, $ port [$ I], & $ errno, & $ errstr, 1 );
    If (! $ Fp ){
    Echo "<tr bgcolor = # FFFFFF> <td align = center> ". $ port [$ I]. "</td> <td> ". $ msg [$ I]. "</td> <td align = center> ". $ close. "</td> <td> ". $ closed. "</td> </tr> ";
    } Else {
    Echo "<tr bgcolor = # F4F7F9> <td align = center> ". $ port [$ I]. "</td> <td> ". $ msg [$ I]. "</td> <td align = center> ". $ open. "</td> <td> ". $ opened. "</td> </tr> ";
    }
    }
    // Use the for statement to connect the port of the remote host using the fsockopen function and output the result.
    Echo "<tr> <td colspan = 4 align = center> ";
    Echo "<a href = portscan. php> <font color = # FFFFFF> Continue scanning >></font> </a> </td> ";
    Echo "</tr ";
    Echo "</table> ";
    Echo "<TABLE cellSpacing = 0 cellPadding = 10 width = 100% border = 0> ";
    Echo "<TR> ";
    Echo "<TD align = center> <B> Port Scan </B> </TD> ";
    Echo "</TR> ";
    Echo "</TABLE> ";
    Echo "</center> ";
    Echo "</body> ";
    Echo "Exit;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.