Initial project's source code check-in.

This commit is contained in:
ptsurbeleu 2011-07-13 16:07:32 -07:00
commit b03b0b373f
4573 changed files with 981205 additions and 0 deletions

View file

@ -0,0 +1,21 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("WebsitePanel.Whois")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyProduct("WebsitePanel.Whois")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("37a8ce5f-0c02-464f-a91b-48e3673dbdff")]

View file

@ -0,0 +1,98 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{7112B144-C5EE-43C2-9441-569D75D13CB9}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>WebsitePanel.Ecommerce.EnterpriseServer</RootNamespace>
<AssemblyName>WebsitePanel.Whois</AssemblyName>
<FileUpgradeFlags>
</FileUpgradeFlags>
<OldToolsVersion>3.5</OldToolsVersion>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
<WarningsAsErrors>618</WarningsAsErrors>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>none</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
<WarningsAsErrors>618</WarningsAsErrors>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\VersionInfo.cs">
<Link>VersionInfo.cs</Link>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="WhoisException.cs" />
<Compile Include="WhoisLookup.cs" />
<Compile Include="WhoisParser.cs" />
<Compile Include="WhoisResult.cs" />
<Compile Include="WhoisSettings.cs" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
<Visible>False</Visible>
<ProductName>Windows Installer 3.1</ProductName>
<Install>true</Install>
</BootstrapperPackage>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View file

@ -0,0 +1,42 @@
// Copyright (c) 2011, Outercurve Foundation.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// - Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// - Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// - Neither the name of the Outercurve Foundation nor the names of its
// contributors may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
using System;
using System.Collections.Generic;
using System.Text;
namespace WebsitePanel.Ecommerce.EnterpriseServer
{
public class WhoisException : Exception
{
public WhoisException(string message)
: base(message)
{
}
}
}

View file

@ -0,0 +1,196 @@
// Copyright (c) 2011, Outercurve Foundation.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// - Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// - Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// - Neither the name of the Outercurve Foundation nor the names of its
// contributors may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
using System;
using System.IO;
using System.Net;
using System.Text;
using System.Net.Sockets;
using System.Collections.Generic;
namespace WebsitePanel.Ecommerce.EnterpriseServer
{
public class WhoisLookup
{
#region Failure messages
public const string GENERIC_FAILURE_MESSAGE = "Could not check the domain availability";
public const string EMPTY_RESPONSE_MESSAGE = "WHOIS server couldn't be reached or returned an empty response";
#endregion
public static WhoisResult Query(string domain, string tld)
{
WhoisResult response = new WhoisResult();
try
{
// check whether tld contains sld parts
// applicable for .*.uk names
string whoisKey = (tld.IndexOf(".") > -1) ? tld.Substring(tld.LastIndexOf(".") + 1) : tld;
// no whois server association for TLD found
if (!WhoisSettings.WhoisServers.Contains(whoisKey))
throw new Exception(GENERIC_FAILURE_MESSAGE);
// get whois server
string whoisServer = (string)WhoisSettings.WhoisServers[whoisKey];
// query whois server for specified domain & tld
StringReader reader = Whois(whoisServer, domain, tld);
// check response is not null
if (reader == null)
throw new Exception(EMPTY_RESPONSE_MESSAGE);
// parse whois response
response = WhoisParser.Parse(domain + "." + tld, whoisServer, reader);
// query succeed
response.Success = true;
}
catch (WhoisException ex)
{
response.Success = false;
response.ResultException = ex;
response.ErrorMessage = ex.Message;
}
catch (Exception ex)
{
response.Success = false;
response.ErrorMessage = ex.Message;
response.ResultException = ex;
}
return response;
}
/// <summary>
/// Get domain TLD
/// </summary>
/// <param name="domain">Domain name</param>
/// <returns>Top level domain</returns>
private static string GetDomainTLD(string domain)
{
if (domain == null)
throw new ArgumentNullException("domain");
int ccStart = domain.LastIndexOf(".");
if (ccStart < 0 || ccStart == domain.Length)
throw new ArgumentException("Domain name has invalid format specified: " + domain);
return domain.Substring(ccStart + 1);
}
/// <summary>
/// Get domain name without TLD
/// </summary>
/// <param name="domain">Domain name</param>
/// <returns>Domain name</returns>
private static string GetDomainName(string domain)
{
if (domain == null)
throw new ArgumentNullException("domain");
int ccStart = domain.LastIndexOf(".");
if (ccStart < 0 || ccStart == domain.Length)
throw new ArgumentException("Domain name has invalid format specified: " + domain);
return domain.Substring(0, ccStart);
}
/// <summary>
/// Perform whois query
/// </summary>
/// <param name="domain">Domain name (FQDN) to query</param>
/// <param name="tld">Domain tld</param>
/// <returns></returns>
private static StringReader Whois(string whoisServer, string domain, string tld)
{
StringReader sr = null;
TcpClient tcp = null;
if (String.IsNullOrEmpty(whoisServer))
throw new ArgumentNullException("whoisServer");
if (String.IsNullOrEmpty(domain))
throw new ArgumentNullException("domain");
if (String.IsNullOrEmpty(tld))
throw new ArgumentNullException("tld");
try
{
// get whois format
string whoisFormat = (string)WhoisSettings.Parsers[whoisServer];
// build whois command
string whoisCommand = String.Concat(domain, ".", tld);
// INTERNIC use domain option to query domain exactly.
// It also affects on the result messages format so be careful.
switch (whoisFormat)
{
case WhoisSettings.INTERNIC:
whoisCommand = "domain " + whoisCommand;
break;
// Forces AFNIC servers to use english language
case WhoisSettings.AFNIC:
whoisCommand = "-l EN " + whoisCommand;
break;
}
// initialize string buffer
StringBuilder builder = new StringBuilder();
// creates a tcp client instance
tcp = new TcpClient();
// trying to connect
tcp.Connect(new IPEndPoint(Dns.GetHostEntry(whoisServer).AddressList[0], 43));
// obtain networkstream reference
NetworkStream netStream = tcp.GetStream();
// create reader
StreamReader reader = new StreamReader(netStream);
// create writer
StreamWriter writer = new StreamWriter(netStream);
// write command to the whois stream
writer.WriteLine(whoisCommand);
// flush written command
writer.Flush();
// read stream to end
while (!reader.EndOfStream)
builder.AppendLine(reader.ReadLine());
// fill string reader
sr = new StringReader(builder.ToString());
}
catch (Exception ex)
{
throw ex;
}
finally
{
if (tcp != null && tcp.Connected)
tcp.Close();
}
return sr;
}
}
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,80 @@
// Copyright (c) 2011, Outercurve Foundation.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// - Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// - Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// - Neither the name of the Outercurve Foundation nor the names of its
// contributors may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
using System;
using System.Collections.Generic;
using System.Text;
namespace WebsitePanel.Ecommerce.EnterpriseServer
{
public class WhoisResult
{
private string domain;
private string[] nameServers;
private bool recordFound;
private bool success;
private string errorMessage;
private Exception resultException;
public string Domain
{
get { return domain; }
set { domain = value; }
}
public string[] NameServers
{
get { return nameServers; }
set { nameServers = value; }
}
public bool RecordFound
{
get { return recordFound; }
set { recordFound = value; }
}
public bool Success
{
get { return success; }
set { success = value; }
}
public string ErrorMessage
{
get { return errorMessage; }
set { errorMessage = value; }
}
public Exception ResultException
{
get { return resultException; }
set { resultException = value; }
}
}
}

View file

@ -0,0 +1,123 @@
// Copyright (c) 2011, Outercurve Foundation.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// - Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// - Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// - Neither the name of the Outercurve Foundation nor the names of its
// contributors may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
namespace WebsitePanel.Ecommerce.EnterpriseServer
{
internal class WhoisSettings
{
public readonly static Hashtable Parsers;
public readonly static Hashtable WhoisServers;
public const string UANIC = "UANIC";
public const string INTERNIC = "INTERNIC";
public const string PIR = "PIR";
public const string EDUCAUSE = "EDUCAUSE";
public const string NOMINET = "NOMINET";
public const string AUREGISTRY = "AUREGISTRY";
public const string EURID = "EURID";
public const string ROMANIAN = "ROMANIAN";
public const string SWITCH = "SWITCH";
public const string NEUSTAR = "NEUSTAR";
public const string NUDOMAINLTD = "NUDOMAINLTD";
public const string NEULEVEL = "NEULEVEL";
public const string AFFILIAS_LTD = "AFFILIAS_LTD";
public const string SIDN = "SIDN";
public const string AFNIC = "AFNIC";
public const string TIERED_ACCESS = "TIERED_ACCESS";
public const string mTLD = "mTLD";
public const string INTERNET_NZ = "InternetNZ";
private WhoisSettings() { }
static WhoisSettings()
{
WhoisServers = new Hashtable();
Parsers = new Hashtable();
InitParsers();
InitWhoisServers();
}
static void InitWhoisServers()
{
WhoisServers.Add("ua", "whois.ua");
WhoisServers.Add("com", "whois.verisign-grs.com");
WhoisServers.Add("cc", "ccwhois.verisign-grs.com");
WhoisServers.Add("net", "whois.verisign-grs.com");
WhoisServers.Add("edu", "whois.educause.net");
WhoisServers.Add("org", "whois.publicinterestregistry.net");
WhoisServers.Add("uk", "whois.nic.uk");
WhoisServers.Add("au", "whois.ausregistry.net");
WhoisServers.Add("us", "whois.nic.us");
WhoisServers.Add("eu", "whois.eu");
WhoisServers.Add("ro", "whois.rotld.ro");
WhoisServers.Add("ch", "whois.nic.ch");
WhoisServers.Add("tv", "tvwhois.verisign-grs.com");
WhoisServers.Add("biz", "whois.biz");
WhoisServers.Add("info", "whois.afilias.net");
WhoisServers.Add("nl", "whois.domain-registry.nl");
WhoisServers.Add("fr", "whois.nic.fr");
WhoisServers.Add("be", "whois.dns.be");
WhoisServers.Add("name", "whois.nic.name");
WhoisServers.Add("mobi", "whois.dotmobiregistry.net");
WhoisServers.Add("nu", "whois.nic.nu");
WhoisServers.Add("nz", "srs-ak.srs.net.nz");
}
static void InitParsers()
{
Parsers.Add("whois.ua", UANIC);
Parsers.Add("whois.nic.nu", NUDOMAINLTD);
Parsers.Add("whois.internic.net", INTERNIC);
Parsers.Add("whois.verisign-grs.com", INTERNIC);
Parsers.Add("ccwhois.verisign-grs.com", INTERNIC);
Parsers.Add("whois.publicinterestregistry.net", PIR);
Parsers.Add("whois.educause.net", EDUCAUSE);
Parsers.Add("whois.nic.uk", NOMINET);
Parsers.Add("whois.ausregistry.net", AUREGISTRY);
Parsers.Add("whois.nic.us", NEUSTAR);
Parsers.Add("whois.eu", EURID);
Parsers.Add("whois.dns.be", EURID);
Parsers.Add("whois.rotld.ro", ROMANIAN);
Parsers.Add("whois.nic.ch", SWITCH);
Parsers.Add("tvwhois.verisign-grs.com", INTERNIC);
Parsers.Add("whois.biz", NEULEVEL);
Parsers.Add("whois.afilias.net", AFFILIAS_LTD);
Parsers.Add("whois.domain-registry.nl", SIDN);
Parsers.Add("whois.nic.fr", AFNIC);
Parsers.Add("whois.nic.name", TIERED_ACCESS);
Parsers.Add("whois.dotmobiregistry.net", mTLD);
Parsers.Add("srs-ak.srs.net.nz", INTERNET_NZ);
}
}
}