Home  >  Article  >  Backend Development  >  PHP implementation of online port scanning example code_PHP tutorial

PHP implementation of online port scanning example code_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:40:37821browse


  1. $youip=$HTTP_SERVER_VARS["REMOTE_ADDR"];
    $remoteip=$HTTP_POST_VARS[remoteip];
    ?>
  2. php实现端口在线检测

  3. if (!empty($remoteip)){
    function err() {
        die(" 对不起,该IP地址不合法

    点击这里返回");
    }
     // 定义提交错误IP的提示信息
    $ips=explode(".",$remoteip);
     // 用.分割IP地址
     if (intval($ips[0])<1 or intval($ips[0])>255 or intval($ips[3])<1 or intval($ips[3]>255)) err();
    // 如果第一段和最后一段IP的数字小于1或者大于255,则提示出错
     if (intval($ips[1])<0 or intval($ips[1])>255 or intval($ips[2])<0 or intval($ips[2]>255)) err();
    // 如果第二段和第三段IP的数字小于0或者大于255,则提示出错
    $closed=此端口目前处于关闭状态。;
    $opened=This port is currently open!;
    $close="Close";
    $open="Open";
    $port=array(21,23,25,79,80,110,135,137,138,139,143,443,445,1433,3306,3389);
    $msg=array(Ftp,Telnet,Sm tp ,Finger,Http,Pop3,Location Service,Netbios-NS,Netbios-DGM,Netbios-SSN,IMAP,Https,Microsoft-DS,MSSQL,MYSQL,Terminal Services);
    // Pass After checking the IP format, use an array to define the service name and status corresponding to each port
    echo "

    ";
    echo " ";
    echo " ";
    echo " ";
    echo "
    The IP you scanned: ".$remoteip."
    ";

    echo " ";
    echo " ";
    echo " ";
    echo " ";
    echo " ";
    echo " ";
    echo " ";
    //Output the displayed table
    for($i=0;$i
    {
    $fp = @fsockopen($remoteip, $port[$i], &$errno, &$errstr, 1);
    if (!$fp) {
    echo "
    < td>".$msg[$i]." ";
    } else {
    echo "";
    }
    }
    // Use the for statement to connect to the relevant ports of the remote host using the fsockopen function, and output the results
    echo "
    echo "
    portServiceDetection resultsdescription
    ".$port[$i]."".$close."".$closed."
    ".$port[$i]." ".$msg[$i]."".$open."".$opened ."
    ";
    echo "Continue scanning>>>< /td> ";
    echo "
    ";

    echo " ";
    echo " ";
    echo " ";
    echo " ";
    echo "
    port scan
    ";

    echo " ";
    echo " ";
    echo " ";
    exit;

    www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/486202.htmlTechArticle?php $youip=$HTTP_SERVER_VARS["REMOTE_ADDR"]; $remoteip=$HTTP_POST_VARS[remoteip]; ? html head titlephp implements port online detection/title meta http-equiv="Content-Type" content="text/h...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn