Skip to content

Instantly share code, notes, and snippets.

@divinity76
Last active March 28, 2022 14:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save divinity76/6dc32be870cf6d2ecd88b7f41579ed3c to your computer and use it in GitHub Desktop.
Save divinity76/6dc32be870cf6d2ecd88b7f41579ed3c to your computer and use it in GitHub Desktop.
ipv4 scanner
<?php
declare(strict_types=1);
$ip_range_start = 0;
$ip_range_start = ip2long("0.5.0.0");
$ip_range_end = 0xFFFFFFFF;
if (0) {
$ip_range_start = ip2long("45.62.204.200");
$ip_range_end = ip2long("45.62.204.230");
}
$worker_count = min(10_000, $ip_range_end - $ip_range_start);
$mh = curl_multi_init();
$unemployed_workers = array();
$employed_workers = array();
for ($i = 0; $i < $worker_count; ++$i) {
$worker = curl_init();
curl_setopt_array($worker, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_ENCODING => 1,
CURLOPT_VERBOSE => 0
));
$unemployed_workers[] = $worker;
}
$work = function () use (&$unemployed_workers, &$employed_workers, &$mh): void {
static $fuk = 0;
for (;;) {
curl_multi_exec($mh, $active);
if ($active < count($employed_workers)) {
break;
}
curl_multi_select($mh);
}
while ($info = curl_multi_info_read($mh)) {
if ($info['msg'] !== \CURLMSG_DONE) {
continue;
}
$worker = $info['handle'];
echo ".";
++$fuk;
if ($fuk === 10000) {
var_dump(curl_getinfo($worker, CURLINFO_EFFECTIVE_URL));
$fuk = 0;
}
$html = curl_multi_getcontent($worker);
if (
// false !== stripos($html,"nginx") ||
false !== stripos($html, "TibiaFun")
) {
echo "found: " . curl_getinfo($worker, CURLINFO_EFFECTIVE_URL) . "\n";
die();
}
//var_dump($html);
curl_multi_remove_handle($mh, $worker);
unset($employed_workers[(int)$worker]);
$unemployed_workers[] = $worker;
}
};
for ($ip = $ip_range_start; $ip <= $ip_range_end; ++$ip) {
while (empty($unemployed_workers)) {
$work();
}
$worker = array_pop($unemployed_workers);
$url = "http://" . long2ip($ip) . "/";
curl_setopt($worker, CURLOPT_URL, $url);
// curl_setopt($worker,CURLOPT_PRIVATE, $url);
curl_multi_add_handle($mh, $worker);
$employed_workers[(int)$worker] = $worker;
}
while (count($employed_workers) > 0) {
$work();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment