note 96422 added to function.shell-exec

From: Date: Fri, 26 Feb 2010 09:59:15 +0000
Subject: note 96422 added to function.shell-exec
Groups: php.notes 
Request: Send a blank email to php-notes+get-166392@lists.php.net to get a copy of this message
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; } } ?> ---- Server IP: 69.147.83.197 Probable Submitter: 84.171.3.245 ---- Manual Page -- http://www.php.net/manual/en/function.shell-exec.php Edit -- https://master.php.net/note/edit/96422 Del: integrated -- https://master.php.net/note/delete/96422/integrated Del: useless -- https://master.php.net/note/delete/96422/useless Del: bad code -- https://master.php.net/note/delete/96422/bad+code Del: spam -- https://master.php.net/note/delete/96422/spam Del: non-english -- https://master.php.net/note/delete/96422/non-english Del: in docs -- https://master.php.net/note/delete/96422/in+docs Del: other reasons-- https://master.php.net/note/delete/96422 Reject -- https://master.php.net/note/reject/96422 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#166392) next »