Page 1 of 1
Word generator based on alphabet
Posted: Fri Oct 01, 2004 4:21 am
by Dr.Brainiac
Hi all,
Im stuck with something. Im trying to make a generator. It will grab info from dns whois every 12 seconds and put it in my mysql database. Herefore i want to generate possible domains without extension (only for .be domains) based on the alphabet.
I have a page that reloads itself every 12 seconds (javascript). Using session variables i should be able to generate a new domainname each time the page reloads.
This far i get, but i have no idea how to generate these words. I started with something simple but im stuck:
Code: Select all
$tekens = array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","-");
if($counter < count($tekens)){
$domain = "";
for($i=0;$i<$aantal;$i++){
$domain .= $tekens[$counter];
}
print($domain);
$counter++;
//do the actual whois lookup and put it to db
}else{
$counter = 0;
$aantal++;
}
where $aantal would be how many times i looped the whole array of $tekens, and $counter would be a counter to loop the array $tekens. These two vars are provided by sessions.
Any idea's to get me started here?
thx a lot
Posted: Fri Oct 01, 2004 4:33 am
by feyd
[php_man]mt_rand[/php_man]() / [php_man]array_rand[/php_man]()
Posted: Fri Oct 01, 2004 8:24 am
by Dr.Brainiac
Thx for the tip.
I accomplished to get it working with mt_rand. The only problem is that it will take a long long time before i get decent results by using a random factor.
Isn't there another way to generate these domainnames not random?
like
a
aa
aaa
ab
abaa
...
I just need to find how to get all possible words by using just the letters of the alphabet, numbers and "-".
Oh and the "-" char cannot be on the first 3 characters of the domainname.
All other suggestions welcome

Posted: Fri Oct 01, 2004 10:39 am
by d_d
It's still going to take a long time if you do it like that. Whats the largest name you are going to test for?
To do up to 6 letter strings there will be 402,321,221 combinations. Do one every 12 seconds and it will take 55,877 days (152 years!) to complete.
(Thats if my maths is correct!)
If you want to do it for a sane lenght string can't you just use a series of for loops?
Code: Select all
<?php
$tekens = array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","-");
for ($a=0;$a<count($tekens);$a++)
{
$domain = $tekens[$a];
//test domain
}
for ($a=0;$a<count($tekens);$a++)
{
for ($b=0;$b<count($tekens);$b++)
{
$domain = $tekens[$a].$tekens[$b];
//test domain
}
}
for ($a=0;$a<count($tekens);$a++)
{
for ($b=0;$b<count($tekens);$b++)
{
for ($c=0;$c<count($tekens);$c++)
{
$domain = $tekens[$a] . $tekens[$b] . $tekens[$c];
//test domain
}
}
}
?>
Not very elegant but works. You proberly want to cut out the obvious bad ones, where there are two '-' or it starts or ends with '-'.
Posted: Fri Oct 01, 2004 12:30 pm
by feyd
here's a stripped down version of something similar I wrote recently for something else.

Code: Select all
<?php
function nextAttempt($characters, $current = '')
{
$current = (string)$current;
$chars = strlen($characters);
$len = strlen($current);
if($len === 0)
{
$text = chr($min);
}
else
{
$rolls = 0;
$text = $current;
$lastchar = $charactersї$chars - 1];
$firstchar = $charactersї0];
for($x = $len - 1; $x >= 0; $x--)
{
if($textї$x] === $lastchar)
{
$rolls++;
$textї$x] = $firstchar;
}
elseif($chr !== false)
{
$chr = strpos($characters,$textї$x]);
$textї$x] = $charactersї$chr + 1];
break;
}
else
{
die('unknown character in stream');
}
}
if($rolls == $len)
$text .= $firstchar;
}
return $text;
}
$str = 'abcdefghijklmnopqrstuvwxyz0123456789-';
$max_length = 20;
$test = $_GETї'last'];
if(strlen($working = nextAttempt( $str, $test )) > $max_length)
{
// stop working
}
else
{
// continue working
}
?>
Posted: Sun Oct 03, 2004 3:25 am
by Dr.Brainiac
d_d wrote:It's still going to take a long time if you do it like that. Whats the largest name you are going to test for?
To do up to 6 letter strings there will be 402,321,221 combinations. Do one every 12 seconds and it will take 55,877 days (152 years!) to complete.
(Thats if my maths is correct!)
Thx a lot for the help guys. I will try this tomorrow, see what it does.
About the 152 years: it does not work like that actually, i had to give a little more information i guess. I will check a few domainnames every second actually with another server. If its a registered one, i will get the whois information and save it. I can only do that every 12 seconds, otherwise i will be banned from the whois.dns.be server. But the DAS server (check if its registered) doesnt use any bans, neither give the whois information.
So if i have a lot of registered domainnames in a row, yes it will take quite some time to get the information. but i guess the system will work fast this way.
Ah well, i am prepared to wait for a long time for that information, its worth it

Posted: Sun Oct 03, 2004 3:37 am
by Dr.Brainiac
feyd wrote:here's a stripped down version of something similar I wrote recently for something else.

From what i see this could work, looks just what i need
Just using some loops will be difficult i think, because the page refreshes itself and i need to continue from the last generation, and not start all over every refresh. No idea how something like that could be done with loops (

).
I also read something about generating easy to remember passwords based on a list of words. markov chains or something like that :s Its not what im looking for but there might be a way to generate 'most likely to be a domainname' names, I still have to look more into this.
Im still brainstorming for other solutions, but didnt come up with anything else at the moment.
Posted: Sun Oct 03, 2004 9:13 am
by feyd
Just using some loops will be difficult i think, because the page refreshes itself and i need to continue from the last generation, and not start all over every refresh. No idea how something like that could be done with loops
you can have the initial value come in from the url, and the current value (after each pass) go into your refresh url.. if you use my code.