PHP 端口扫描器改写第二次

参考了别人写的代码感觉还是有很多问题!

<?php 

$portarr=array(
'21'=>'FTP',
'22'=>'SSH',
'23'=>'Telnet',
'25'=>'SMTP',
'79'=>'Finger',
'80'=>'HTTP',
'81'=>'HTTP/Proxy',
'110'=>'POP3',
'135'=>'MS Netbios',
'139'=>'MS Netbios',
'143'=>'IMAP',
'162'=>'SNMP',
'389'=>'LDAP',
'443'=>'HTTPS',
'445'=>'MS SMB',
'873'=>'rsync',
'1080'=>'Proxy/HTTP Server',
'1433'=>'MS SQL Server',
'2433'=>'MS SQL Server Hidden',
'1521'=>'Oracle DB Server',
'1522'=>'Oracle DB Server',
'3128'=>'Squid Cache Server',
'3129'=>'Squid Cache Server',
'3306'=>'MySQL Server',
'3307'=>'MySQL Server',
'3500'=>'Squid Cache Server',
'3389'=>'MS Terminal Service',
'5800'=>'VNC Server',
'5900'=>'VNC Server',
'8080'=>'Proxy/HTTP Server',
'10000'=>'Webmin',
'11211'=>'Memcached'
);

function Scan($ip,$port,$overtime=1){
    $conn=@fsockopen($ip,$port,$errno,$errstr,$overtime);
    if ($conn) {
         fclose($conn);
         return true;
    }

};
$a=Scan("hack.dj","80");
if ($a) {
    # code...
//  echo "ok";
}

@$ip=$_POST['Ip'];

if (isset($_POST['Scan'])) {
    if (strpos($ip, '-')) {
            //多IP扫描代码
            $a=explode ('-', $ip);  //arr
            $b=$a[1];               //后面氛围IP
            $d=explode('.', $a[0]);  //前段整段IP
            $e=$d[3];
            $value = (int)$b-(int)$e ;

            for ($i=0; $i <=$value ; $i++) { 
            $ip = "$d[0].$d[1].$d[2].$e";
            $e++;
            foreach ($portarr as $port => $name) {
                if (Scan($ip,$port)) {
                    # code...
                    echo "$ip $port open <br>";
                }
                # code...
            }
            }
            }

            else {
            //单IP扫描代码
            foreach ($portarr as $port => $name) {          
            if (Scan($ip,$port)) {
            echo "$ip $port open<br>";
            }
            }
};
};

 ?>

 <!DOCTYPE html>
 <html>
 <head>
    <title>Demo</title>
 </head>
 <body>
<form method="post" action="#">
IP: <input type="text" name="Ip"> 
    <input type="submit" name="Scan" value="Scan">
</form>
 </body>
 </html>

最终版本 :
AJAX写的,后端代码没几行,不想在起一篇文章了.
http://php.ph/PortScan.html

标签: none

添加新评论