How to get opened ports of a remote server in PHP?
Or is it possibl开发者_StackOverflowe?
look at 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";
}
?>
exec nmap and parse the result
精彩评论