Skip to content

Instantly share code, notes, and snippets.

@key-moon

key-moon/fam.php Secret

Created October 8, 2018 02:00
Show Gist options
  • Save key-moon/807e10e9128380c9b8eb26b87b85ad34 to your computer and use it in GitHub Desktop.
Save key-moon/807e10e9128380c9b8eb26b87b85ad34 to your computer and use it in GitHub Desktop.
<?php
$ip = $_POST["ip"];
if ($ip) {
// super fancy regex check!
if (preg_match('/^(([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]).){3}([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])/',$ip)) {
exec('ping -c 1 '.$ip, $cmd_result);
foreach($cmd_result as $str){
if (strpos($str, '100% packet loss') !== false){
printf("<h3>Target is NOT alive.</h3>");
break;
} else if (strpos($str, ', 0% packet loss') !== false){
printf("<h3>Target is alive.</h3>");
break;
}
}
} else {
echo "Wrong IP Format.";
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment