php 埠掃描
阿新 • • 發佈:2019-01-01
<?php
$iparea = '10.10.3.*';
$ports = explode(',', '80,8080,8000,81,8888,82,3306,3389,23,21,22,11211,6379,27017');
$openlist = '';
for($i=0;$i<255;$i++){
$ip = str_replace('*', $i, $iparea );
foreach($ports as $port){
$line = "{$ip}:{$port}:";
if(check_port($ip,$port,$timeout=0.5)){
$line .= "open\n";
$openlist .= $line;
}else{
$line .= "close\n";
}
echo $line;
}
}
if($openlist!='')
echo "\n=============\n{$openlist}";
function check_port($ip,$port,$timeout=0.1) {
$conn = @fsockopen($ip, $port, $errno, $errstr, $timeout);
if ($conn) {
fclose($conn);
return true;
}
}
$iparea = '10.10.3.*';
$ports = explode(',', '80,8080,8000,81,8888,82,3306,3389,23,21,22,11211,6379,27017');
$openlist = '';
for($i=0;$i<255;$i++){
$ip = str_replace('*', $i, $iparea );
foreach($ports as $port){
$line = "{$ip}:{$port}:";
if(check_port($ip,$port,$timeout=0.5)){
$line .= "open\n";
$openlist .= $line;
}else{
$line .= "close\n";
}
echo $line;
}
}
if($openlist!='')
echo "\n=============\n{$openlist}";
function check_port($ip,$port,$timeout=0.1) {
$conn = @fsockopen($ip, $port, $errno, $errstr, $timeout);
if ($conn) {
fclose($conn);
return true;
}
}