note 96422 deleted from function.shell-exec by cmb
| From: | cmb@php.net | Date: | Sun, 14 Jul 2019 11:36:13 +0000 |
| Subject: | note 96422 deleted from function.shell-exec by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-211593@lists.php.net to get a copy of this message | ||
Note Submitter: nowayoutlive.de
----
Today I needed a piece of code, which makes use of the shell_exec function. For those who want to
scan 2 letter domains too, here is a nice linux and php5 way, using a character generator class.
<?php
define("__USED_CHARS__", "abcdefghijklmnopqrstuvwxyz0123456789");
define("__CASE_SENSITIVE__", true); // Use string above or use uppercase / lowercase
variant
$bf = new chargen(2); // new chargen object, length 2
$bf->generate("whois"); // generate chars and call whois function
function whois($str)
{
$domain = $str.".com";
$retval = shell_exec("whois $domain");
if (eregi("no match", $retval))
echo $domain." ist available\n";
else
echo $domain." is unavailable\n";
}
class chargen
{
private $chars = NULL;
private $maxlength = NULL;
protected $buffer = NULL;
function generate($mycallback = false)
{
foreach ($this->buffer as $char)
{
foreach ($this->chars as $nextchar)
{
$retval = $char.$nextchar;
$this->buffer[$retval] = $retval;
if ($mycallback && function_exists($mycallback))
$mycallback($retval);
else
echo $retval."\n";
}
}
if (strlen($retval) == $this->maxlength)
return;
$this->generate($mycallback);
}
function __construct($maxlength = 8)
{
$chars = array();
$this->buffer = array();
array_push($this->buffer, "");
for ($i = 0; $i < strlen(__USED_CHARS__); $i++)
{
$index = substr(__USED_CHARS__, $i, 1);
if (__CASE_SENSITIVE__)
{
$this->chars[$index] = $index;
}
else
{
$this->chars[strtolower($index)] = strtolower($index);
$this->chars[strtoupper($index)] = strtoupper($index);
}
}
$this->maxlength = $maxlength;
}
}
?>