掃描端口腳本 -- PHP CLI 版本

<?php
//掃描端口腳本 -- PHP CLI 版本
if(!extension_loaded('sockets')){
    die('sockets has not open');
}

echo 'Please enter the host name or IP address'."\r\n";
$host = trim(fgets(STDIN));
$host = str_replace('http://','',$host);
$host = str_replace('https://','',$host);

//如果輸入的不是IP地址,嘗試轉換成IP地址
if(!filter_var($host,FILTER_VALIDATE_IP)){
    $host = gethostbyname($host);
}

echo 'Please enter the ports by scanner'."\r\n";
$ports = trim(fgets(STDIN));
$ports = explode(',',str_replace(",",",",$ports));

echo 'Please enter the timeout ,Default 30 second';
$timeout = trim(fgets(STDIN));
if(!$timeout){
    $timeout = 30;
}

foreach ($ports as $port) {
    //創建一個套接字,成功則端口打開。
    $conn = @fsockopen($host,$port,$error_no,$error_str,$timeout);
    if($conn){
        fclose($conn);
        echo $host.':'.$port.' is open'."\r\n";
    }else{
        echo $host.':'.$port.' is close'."\r\n";
    }
}

?>

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章