Skip to content

Instantly share code, notes, and snippets.

@heylastway
Created November 1, 2019 13:26
Show Gist options
  • Save heylastway/71dff032bdbdd51dbdfd67ab2351efb6 to your computer and use it in GitHub Desktop.
Save heylastway/71dff032bdbdd51dbdfd67ab2351efb6 to your computer and use it in GitHub Desktop.
<?php
error_reporting(0);
/**
*
*/
class Ipscanner
{
var $timeout;
function banner(){
echo "------------------------------------\r\n";
echo "-- SIMPLE IP SCANNER --\r\n";
echo "------------------------------------\r\n";
echo "[Scan] ".$this->ip."\r\n\n";
}
function pesan($pesan){
echo "[".date("H:i:s")."] ".$pesan."\r\n";
}
function scan($ip)
{
$this->ip = $ip;
$ip = explode("-", $ip);
$start = explode(".", $ip[0]);
$this->banner();
for ($i=0; $i <3; $i++) {
$ips .= $start[$i].".";
}
echo $this->timeout;
for ($i=$start[3]; $i <$ip[1]+1; $i++) {
$ch = curl_init($ips.$i);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT ,0);
curl_setopt ($ch, CURLOPT_TIMEOUT, 2);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if($httpcode>=200 && $httpcode<300){
$this->pesan($ips.$i." -> Live");
$live[] = $ips.$i;
} else {
$this->pesan($ips.$i." -> Die");
$die[] = $ips.$i;
}
}
echo "---- [ IP LIVE ] ----\r\n";
foreach ($live as $key => $ip) {
echo " > ".$ip."\r\n";
}
}
}
$ipscanner = new Ipscanner;
$ipscanner->scan("192.168.1.1-255");
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment