| | |||||
| ||||||||
| 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. |
![]() |
| | LinkBack | Thread Tools |
| | THREAD STARTER #1 (permalink) |
| NamePros Regular Join Date: Jul 2004 Location: Seattle, Wa
Posts: 596
![]() ![]() ![]() | 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
|
| |
| | #2 (permalink) |
| NamePros Regular Join Date: Jun 2004 Location: Iowa City
Posts: 703
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | 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 |
| |
| | #3 (permalink) |
| NamePros Expert Join Date: Nov 2003 Location: Scotland
Posts: 5,074
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | 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 |
| |