dongyi2993 2014-11-14 10:52
浏览 16

如何用php检查端口2082和2222以检测服务器的控制面板

How can i check ports 2082, 2222 with php to detect control panel of server?

$ports = array(2082 => 'cpanel', 2222 => 'directadmin' , ....);
$panel = "";

foreach($ports as $port => $panelName){
   // some codes for checking the port's
   // if(something)
         $panel = $panelName;
}
  • 写回答

1条回答 默认 最新

  • duanpuluan0480 2015-11-21 15:37
    关注

    there is no straight forward solution for this, you need to implement your own creative method. you may need to detect one control panel with opening socket,while other using an specific file existence (ex. Cpanel puts api files on php include path) or any other idea.

    you can use this class for this purpose

    namespace Model;
    
    // usage:
    //include 'detectControlPanel';
    //$object = new \model\detectControlPanel();
    //$result = $object->getDetect();
    //var_dump($result);
    
    class detectControlPanel
    {
    public $debug = false;
    protected $detect = array();
    
    public function getDetect()
    {
        return $this->detect;
    }
    
    public function __construct($debug = false)
    {
        $this->run();
        $this->debug = $debug;
        $this->debug($this->detect);
    }
    
    public function run()
    {
        $this->detect['cpanel'] = $this->isCpanel();
        $this->detect['virtualmin'] = $this->isVirtualmin();
        $this->detect['plesk'] = $this->isPlesk();
        $this->detect['directadmin'] = $this->isDirectadmin();
        return $this->detect;
    }
    
    private function isCpanel()
    {
        try {
            $this->telnet('localhost', 2082);
            return true;
        } catch (\Exception $ex) {
            $this->debug($ex);
            return false;
        }
    }
    
    private function isVirtualmin()
    {
        try {
            $this->telnet('localhost', 10000);
            return true;
        } catch (\Exception $ex) {
            $this->debug($ex);
            return false;
        }
    }
    
    private function isDirectadmin()
    {
        try {
            $this->telnet('localhost', 2222);
            return true;
        } catch (\Exception $ex) {
            $this->debug($ex);
            return false;
        }
    }
    
    private function isPlesk()
    {
        try {
            $this->telnet('localhost', 8443);
            return true;
        } catch (\Exception $ex) {
            $this->debug($ex);
            return false;
        }
    }
    
    private function debug($input)
    {
        if ($this->debug == true) {
            if (gettype($input) == 'string') {
                echo '<br>' . "
    ";
                echo $input;
                echo '<br>' . "
    ";
            } elseif (gettype($input) == 'array') {
                echo '<pre>' . "
    ";
                print_r($input);
                echo '</pre>' . "
    ";
            } elseif (gettype($input) == 'object' && get_class($input) == 'Exception') {
                echo '<pre>' . "
    ";
                echo $input->getMessage();
                echo '</pre>' . "
    ";
            } else {
                var_dump($input);
            }
        }
    }
    
    private function telnet($hostname, $port)
    {
        if (!$hostname)
            throw new \Exception("empty host name");
        if (!$port)
            throw new \Exception("empty port number");
        $ipAddress = gethostbyname($hostname);
        $link = @fsockopen($ipAddress, $port, $errno, $error);
        if ($error) {
            throw new \Exception($error, $errno);
        }
        if ($link) {
            return true;
        }
        return false;
    }
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度