简体   繁体   English

如何在PHP中获取远程服务器的打开端口?

[英]How to get opened ports of a remote server in PHP?

还是可能吗?

您几乎必须使用PHP编写端口扫描程序。

look at http://www.phpclasses.org/browse/package/1581.html 看看http://www.phpclasses.org/browse/package/1581.html

the file is : 该文件是:

<?php 
//Author: Sean Burke 
//Version: 1.0 
//This Class aids in determining the status of ports and also what service they are. 
//To contribute to the port listing email your lists  to seanb@lcnhosting.com 
class portscan { 
    var $port, 
    $host, 
    $action, 
    $result, 
    $pname, 
    $plist, 
    $sresult, 
    $hlist; 
    function status() { 
        $sc=socket_create (AF_INET, SOCK_STREAM, getprotobyname("TCP")); 
        if (@socket_connect($sc,$this->host,$this->port)) { 
            $this->result="open\n"; 
        } 
        else { 
            $this->result="closed\n"; 
        } 
    } 
    function name() { 
        $fp=fopen('ports.txt','r'); 
        $temp=fread($fp,filesize('ports.txt')); 
        fclose($fp); 
        $temp=explode("\n",$temp); 
        for($a=0;$a<sizeof($temp);$a++) { 
            $temp2=explode("||",$temp[$a]); 
            if ($this->port==$temp2[0]) { 
                    $this->pname=$temp2[1]; 
                    $found==1; 
            } 
        } 
        if ($found==NULL) { 
            $this->pname=="NA"; 
        } 
    } 
    function scan($sfile) { 
        if(is_file($sfile)) { 
            $fp=fopen($sfile,'r'); 
            $file=$sfile; 
        } 
        else { 
            $fp=fopen('ports.txt','r'); 
            $file='ports.txt'; 
        } 
        $temp=fread($fp,filesize($file)); 
        fclose($fp); 
        $temp=explode("\n",$temp); 
        for($a=0;$a<sizeof($temp);$a++) { 
            $temp2=explode("||",$temp[$a]); 
            if($temp2[0]!=NULL) { 
                $this->port=$temp2[0]; 
                $this->status(); 
                $this->name(); 
                $this->sresult[$a]=$this->port."||".$this->result."||".$this->pname; 
            } 
        } 
    } 

} 
$scan=new portscan; 
$scan->port=80; 
$scan->host="lcnhosting.com"; 
$scan->status(); 
$scan->name(); 
print "PORT: ".$scan->port.": ".$scan->result." SERVICE: ".$scan->pname."\n";  
$scan->scan(NULL); 
print sizeof($scan->sresult)."\n"; 
for($a=0;$a<sizeof($scan->sresult);$a++) { 
    print $scan->sresult[$a]."\n"; 
} 
?> 

执行nmap并解析结果

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM