NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming > CODE
Reload this Page Available Random Domain Generator in C#

CODE This forum is for posting code snippets and example scripts that aren't quite tutorials, but could be useful for others. You may post code snippets and/or completed scripts that you've written and want to share here.

Advanced Search
7 members in live chat ~  


Closed Thread
 
LinkBack Thread Tools
Old 11-22-2007, 01:25 AM THREAD STARTER               #1 (permalink)
NamePros Regular
 
Palyriot's Avatar
Join Date: Jul 2004
Location: Seattle, Wa
Posts: 596
Palyriot is a jewel in the roughPalyriot is a jewel in the roughPalyriot is a jewel in the rough
 



Available Random Domain Generator in C#


I was bored and decided to make an available random domain generator in C#, inspired by Jim_'s thread, Available 3-Character Domain Scanner. I know some of you are going to complain that it may spam whois servers, but you can just add a few more whois websites to the "whoisWebsites" array. It's not commented, because I hate commenting, but if there are any questions, feel free to ask. I also know that people will fix and add stuff to this, so feel free to.

Code:
using System;
using System.Text;
using System.Net;

class Program
{
    static Random rand = new Random();

    static void Main()
    {
        //Config
        const int NUMBER_OF_DOMAINS_TO_CHECK = 10; //Will actually check this amount multiplied by the number of extensions listed below.
        const int LENGTH_OF_DOMAINS = 4;
        const bool UPPERCASE = false;
        string[] extensions = new string[] {"com", "net", "org"};

        Console.WriteLine("Checking {0} domains: \n", (NUMBER_OF_DOMAINS_TO_CHECK * extensions.Length));

        int domainCount = 0;
        for (int i = 1; i <= NUMBER_OF_DOMAINS_TO_CHECK; i++)
        {
            string domain = CreateDomain(LENGTH_OF_DOMAINS, UPPERCASE);
            

            foreach (string extension in extensions)
            {
                Console.Write(domain + "." + extension);

                if (CheckDomain(domain + "." + extension))
                {
                    Console.WriteLine(" <---Available---");
                    domainCount++;
                }
                else
                {
                    Console.WriteLine();
                }
            }
        }
        if (domainCount != 0)
            Console.WriteLine("\n{0} available domains found.", domainCount);
        else
            Console.WriteLine("No domains found.");


        Console.Read();
    }

    static bool CheckDomain(string domain)
    {
        string[] whoisWebsites = new string[] {"http://registrar.verisign-grs.com/cgi-bin/whois?whois_nic="};
        WebClient reader = new WebClient();
        string url = whoisWebsites[rand.Next(0, whoisWebsites.Length - 1)] + domain;
        byte[] reqHTML;
        reqHTML = reader.DownloadData(url);
        UTF8Encoding objUTF8 = new UTF8Encoding();
        string contents = objUTF8.GetString(reqHTML);

        if (contents.IndexOf("No match") == -1 && contents.IndexOf("Not Found") == -1)
        {
            return false;
        }
        else
        {
            return true;
        }
    }

    static string CreateDomain(int length, bool uppercase)
    {
        string domain = null;

        for (int i = 1; i <= length; i++)
        {
            char letter = (char)rand.Next(97, 123);
            domain += letter.ToString();
        }

        if (uppercase)
            domain = domain.ToUpper();

        return domain;
        
    }
}
Last edited by Palyriot; 11-22-2007 at 01:42 AM. Reason: PIR currently restrict whois access for the general public to 4 lookups
Palyriot is offline  
Old 11-28-2007, 05:02 AM   #2 (permalink)
NamePros Regular
 
nick's Avatar
Join Date: Jun 2004
Location: Iowa City
Posts: 703
nick has much to be proud ofnick has much to be proud ofnick has much to be proud ofnick has much to be proud ofnick has much to be proud ofnick has much to be proud ofnick has much to be proud ofnick has much to be proud of
 


Save The Children
This looks pretty cool.

I will give it a try later. I always looked for C# domain tools
__________________
formally ninedogger
------
Want to talk to a stranger? -->| Click Here | TalkToAStranger.com | <-- Meet New Friends
nick is offline  
Old 11-28-2007, 08:46 AM   #3 (permalink)
NamePros Expert
 
Peter's Avatar
Join Date: Nov 2003
Location: Scotland
Posts: 5,074
Peter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond repute
 


Child Abuse Save The Children Save The Children Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009
very neat indeed.

If anyone is unsure at the moment the tool creates random domain names of 4 characters. It then checks whether the .com, .net and .org are taken for that phrase. It does this for 10 phrases at a time.
__________________
Manage your portfolio using my new Domain Portfolio Management script.
Securing Your Domain Name From Theft
Peter is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


 
All times are GMT -7. The time now is 07:15 PM.

Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger