├── .gitattributes
├── .gitignore
├── DomainTools.Demo
├── App.config
├── DomainTools.Demo.csproj
├── Program.cs
└── Properties
│ └── AssemblyInfo.cs
├── DomainTools.sln
├── DomainTools
├── DomainTools.csproj
├── Properties
│ └── AssemblyInfo.cs
├── RecordType.cs
├── Whois.cs
└── WhoisServerResolver.cs
└── README.md
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 |
4 | # User-specific files
5 | *.suo
6 | *.user
7 | *.userosscache
8 | *.sln.docstates
9 |
10 | # User-specific files (MonoDevelop/Xamarin Studio)
11 | *.userprefs
12 |
13 | # Build results
14 | [Dd]ebug/
15 | [Dd]ebugPublic/
16 | [Rr]elease/
17 | [Rr]eleases/
18 | x64/
19 | x86/
20 | build/
21 | bld/
22 | [Bb]in/
23 | [Oo]bj/
24 |
25 | # Visual Studio 2015 cache/options directory
26 | .vs/
27 |
28 | # MSTest test Results
29 | [Tt]est[Rr]esult*/
30 | [Bb]uild[Ll]og.*
31 |
32 | # NUNIT
33 | *.VisualState.xml
34 | TestResult.xml
35 |
36 | # Build Results of an ATL Project
37 | [Dd]ebugPS/
38 | [Rr]eleasePS/
39 | dlldata.c
40 |
41 | # DNX
42 | project.lock.json
43 | artifacts/
44 |
45 | *_i.c
46 | *_p.c
47 | *_i.h
48 | *.ilk
49 | *.meta
50 | *.obj
51 | *.pch
52 | *.pdb
53 | *.pgc
54 | *.pgd
55 | *.rsp
56 | *.sbr
57 | *.tlb
58 | *.tli
59 | *.tlh
60 | *.tmp
61 | *.tmp_proj
62 | *.log
63 | *.vspscc
64 | *.vssscc
65 | .builds
66 | *.pidb
67 | *.svclog
68 | *.scc
69 |
70 | # Chutzpah Test files
71 | _Chutzpah*
72 |
73 | # Visual C++ cache files
74 | ipch/
75 | *.aps
76 | *.ncb
77 | *.opensdf
78 | *.sdf
79 | *.cachefile
80 |
81 | # Visual Studio profiler
82 | *.psess
83 | *.vsp
84 | *.vspx
85 |
86 | # TFS 2012 Local Workspace
87 | $tf/
88 |
89 | # Guidance Automation Toolkit
90 | *.gpState
91 |
92 | # ReSharper is a .NET coding add-in
93 | _ReSharper*/
94 | *.[Rr]e[Ss]harper
95 | *.DotSettings.user
96 |
97 | # JustCode is a .NET coding add-in
98 | .JustCode
99 |
100 | # TeamCity is a build add-in
101 | _TeamCity*
102 |
103 | # DotCover is a Code Coverage Tool
104 | *.dotCover
105 |
106 | # NCrunch
107 | _NCrunch_*
108 | .*crunch*.local.xml
109 |
110 | # MightyMoose
111 | *.mm.*
112 | AutoTest.Net/
113 |
114 | # Web workbench (sass)
115 | .sass-cache/
116 |
117 | # Installshield output folder
118 | [Ee]xpress/
119 |
120 | # DocProject is a documentation generator add-in
121 | DocProject/buildhelp/
122 | DocProject/Help/*.HxT
123 | DocProject/Help/*.HxC
124 | DocProject/Help/*.hhc
125 | DocProject/Help/*.hhk
126 | DocProject/Help/*.hhp
127 | DocProject/Help/Html2
128 | DocProject/Help/html
129 |
130 | # Click-Once directory
131 | publish/
132 |
133 | # Publish Web Output
134 | *.[Pp]ublish.xml
135 | *.azurePubxml
136 | ## TODO: Comment the next line if you want to checkin your
137 | ## web deploy settings but do note that will include unencrypted
138 | ## passwords
139 | #*.pubxml
140 |
141 | *.publishproj
142 |
143 | # NuGet Packages
144 | *.nupkg
145 | # The packages folder can be ignored because of Package Restore
146 | **/packages/*
147 | # except build/, which is used as an MSBuild target.
148 | !**/packages/build/
149 | # Uncomment if necessary however generally it will be regenerated when needed
150 | #!**/packages/repositories.config
151 |
152 | # Windows Azure Build Output
153 | csx/
154 | *.build.csdef
155 |
156 | # Windows Store app package directory
157 | AppPackages/
158 |
159 | # Visual Studio cache files
160 | # files ending in .cache can be ignored
161 | *.[Cc]ache
162 | # but keep track of directories ending in .cache
163 | !*.[Cc]ache/
164 |
165 | # Others
166 | ClientBin/
167 | [Ss]tyle[Cc]op.*
168 | ~$*
169 | *~
170 | *.dbmdl
171 | *.dbproj.schemaview
172 | *.pfx
173 | *.publishsettings
174 | node_modules/
175 | orleans.codegen.cs
176 |
177 | # RIA/Silverlight projects
178 | Generated_Code/
179 |
180 | # Backup & report files from converting an old project file
181 | # to a newer Visual Studio version. Backup files are not needed,
182 | # because we have git ;-)
183 | _UpgradeReport_Files/
184 | Backup*/
185 | UpgradeLog*.XML
186 | UpgradeLog*.htm
187 |
188 | # SQL Server files
189 | *.mdf
190 | *.ldf
191 |
192 | # Business Intelligence projects
193 | *.rdl.data
194 | *.bim.layout
195 | *.bim_*.settings
196 |
197 | # Microsoft Fakes
198 | FakesAssemblies/
199 |
200 | # Node.js Tools for Visual Studio
201 | .ntvs_analysis.dat
202 |
203 | # Visual Studio 6 build log
204 | *.plg
205 |
206 | # Visual Studio 6 workspace options file
207 | *.opt
208 |
209 | # LightSwitch generated files
210 | GeneratedArtifacts/
211 | _Pvt_Extensions/
212 | ModelManifest.xml
213 |
--------------------------------------------------------------------------------
/DomainTools.Demo/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/DomainTools.Demo/DomainTools.Demo.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {51493B96-AE3A-483F-93F2-A3AB057D24A5}
8 | Exe
9 | Properties
10 | DomainTools.Demo
11 | DomainTools.Demo
12 | v4.5.2
13 | 512
14 | true
15 |
16 |
17 | AnyCPU
18 | true
19 | full
20 | false
21 | bin\Debug\
22 | DEBUG;TRACE
23 | prompt
24 | 4
25 |
26 |
27 | AnyCPU
28 | pdbonly
29 | true
30 | bin\Release\
31 | TRACE
32 | prompt
33 | 4
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 | {352a533a-aa80-405f-a614-9aefa3e93eb4}
55 | DomainTools
56 |
57 |
58 |
59 |
66 |
--------------------------------------------------------------------------------
/DomainTools.Demo/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace DomainTools.Demo
8 | {
9 | class Program
10 | {
11 | static void Main(string[] args)
12 | {
13 | Console.WriteLine("Enter a domain name to get the whois information.");
14 | var domainName = Console.ReadLine();
15 | try
16 | {
17 | var whoisText = Whois.Lookup(domainName, RecordType.domain);
18 | Console.WriteLine(whoisText);
19 | }
20 | catch (Exception ex)
21 | {
22 | Console.WriteLine(ex.ToString());
23 | }
24 |
25 | Console.WriteLine("Press any key to exit..");
26 | Console.Read();
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/DomainTools.Demo/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("DomainTools.Demo")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("DomainTools.Demo")]
13 | [assembly: AssemblyCopyright("Copyright © 2015")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("51493b96-ae3a-483f-93f2-a3ab057d24a5")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/DomainTools.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 14
4 | VisualStudioVersion = 14.0.23107.0
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DomainTools", "DomainTools\DomainTools.csproj", "{352A533A-AA80-405F-A614-9AEFA3E93EB4}"
7 | EndProject
8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DomainTools.Demo", "DomainTools.Demo\DomainTools.Demo.csproj", "{51493B96-AE3A-483F-93F2-A3AB057D24A5}"
9 | EndProject
10 | Global
11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
12 | Debug|Any CPU = Debug|Any CPU
13 | Release|Any CPU = Release|Any CPU
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {352A533A-AA80-405F-A614-9AEFA3E93EB4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
17 | {352A533A-AA80-405F-A614-9AEFA3E93EB4}.Debug|Any CPU.Build.0 = Debug|Any CPU
18 | {352A533A-AA80-405F-A614-9AEFA3E93EB4}.Release|Any CPU.ActiveCfg = Release|Any CPU
19 | {352A533A-AA80-405F-A614-9AEFA3E93EB4}.Release|Any CPU.Build.0 = Release|Any CPU
20 | {51493B96-AE3A-483F-93F2-A3AB057D24A5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21 | {51493B96-AE3A-483F-93F2-A3AB057D24A5}.Debug|Any CPU.Build.0 = Debug|Any CPU
22 | {51493B96-AE3A-483F-93F2-A3AB057D24A5}.Release|Any CPU.ActiveCfg = Release|Any CPU
23 | {51493B96-AE3A-483F-93F2-A3AB057D24A5}.Release|Any CPU.Build.0 = Release|Any CPU
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | EndGlobal
29 |
--------------------------------------------------------------------------------
/DomainTools/DomainTools.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {352A533A-AA80-405F-A614-9AEFA3E93EB4}
8 | Library
9 | Properties
10 | DomainTools
11 | DomainTools
12 | v4.5.2
13 | 512
14 |
15 |
16 | true
17 | full
18 | false
19 | bin\Debug\
20 | DEBUG;TRACE
21 | prompt
22 | 4
23 |
24 |
25 | pdbonly
26 | true
27 | bin\Release\
28 | TRACE
29 | prompt
30 | 4
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
56 |
--------------------------------------------------------------------------------
/DomainTools/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("DomainTools")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("DomainTools")]
13 | [assembly: AssemblyCopyright("Copyright © 2015")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("352a533a-aa80-405f-a614-9aefa3e93eb4")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/DomainTools/RecordType.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace DomainTools
8 | {
9 | public enum RecordType
10 | {
11 | domain,
12 | nameserver,
13 | registrar
14 | };
15 | }
16 |
--------------------------------------------------------------------------------
/DomainTools/Whois.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Linq;
5 | using System.Net.Sockets;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace DomainTools
10 | {
11 | ///
12 | /// A class to lookup whois information.
13 | ///
14 | public class Whois
15 | {
16 | private const int Whois_Server_Default_PortNumber = 43;
17 |
18 | ///
19 | /// Retrieves whois information
20 | ///
21 | /// The registrar or domain or name server whose whois information to be retrieved
22 | /// The type of record i.e a domain, nameserver or a registrar
23 | ///
24 | public static string Lookup(string domainName, RecordType recordType)
25 | {
26 | string whoisServerName = WhoisServerResolver.GetWhoisServerName(domainName);
27 | using (TcpClient whoisClient = new TcpClient())
28 | {
29 | whoisClient.Connect(whoisServerName, Whois_Server_Default_PortNumber);
30 |
31 | string domainQuery = recordType.ToString() + " " + domainName + "\r\n";
32 | byte[] domainQueryBytes = Encoding.ASCII.GetBytes(domainQuery.ToCharArray());
33 |
34 | Stream whoisStream = whoisClient.GetStream();
35 | whoisStream.Write(domainQueryBytes, 0, domainQueryBytes.Length);
36 |
37 | StreamReader whoisStreamReader = new StreamReader(whoisClient.GetStream(), Encoding.ASCII);
38 |
39 | string streamOutputContent = "";
40 | List whoisData = new List();
41 | while (null != (streamOutputContent = whoisStreamReader.ReadLine()))
42 | {
43 | whoisData.Add(streamOutputContent);
44 | }
45 |
46 | whoisClient.Close();
47 |
48 | return String.Join(Environment.NewLine, whoisData);
49 | }
50 | }
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/DomainTools/WhoisServerResolver.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace DomainTools
8 | {
9 | public class WhoisServerResolver
10 | {
11 | //;WHOIS Servers List
12 | //;Maintained by Nir Sofer
13 | //;This servers list if freely available for any use and without any restriction.
14 | //;For more information: http://www.nirsoft.net/whois_servers_list.html
15 | //;Last updated on 09/03/2014
16 | private static Dictionary WhoisServerCollection = new Dictionary()
17 | {
18 | {"ac", "whois.nic.ac"},
19 | {"ae", "whois.aeda.net.ae"},
20 | {"aero", "whois.aero"},
21 | {"af", "whois.nic.af"},
22 | {"ag", "whois.nic.ag"},
23 | {"al", "whois.ripe.net"},
24 | {"am", "whois.amnic.net"},
25 | {"as", "whois.nic.as"},
26 | {"asia", "whois.nic.asia"},
27 | {"at", "whois.nic.at"},
28 | {"au", "whois.aunic.net"},
29 | {"ax", "whois.ax"},
30 | {"az", "whois.ripe.net"},
31 | {"ba", "whois.ripe.net"},
32 | {"be", "whois.dns.be"},
33 | {"bg", "whois.register.bg"},
34 | {"bi", "whois.nic.bi"},
35 | {"biz", "whois.neulevel.biz"},
36 | {"bj", "www.nic.bj"},
37 | {"br", "whois.nic.br"},
38 | {"br.com", "whois.centralnic.com"},
39 | {"bt", "whois.netnames.net"},
40 | {"by", "whois.cctld.by"},
41 | {"bz", "whois.belizenic.bz"},
42 | {"ca", "whois.cira.ca"},
43 | {"cat", "whois.cat"},
44 | {"cc", "whois.nic.cc"},
45 | {"cd", "whois.nic.cd"},
46 | {"ch", "whois.nic.ch"},
47 | {"ck", "whois.nic.ck"},
48 | {"cl", "whois.nic.cl"},
49 | {"cn", "whois.cnnic.net.cn"},
50 | {"cn.com", "whois.centralnic.com"},
51 | {"co", "whois.nic.co"},
52 | {"co.nl", "whois.co.nl"},
53 | {"com", "whois.verisign-grs.com"},
54 | {"coop", "whois.nic.coop"},
55 | {"cx", "whois.nic.cx"},
56 | {"cy", "whois.ripe.net"},
57 | {"cz", "whois.nic.cz"},
58 | {"de", "whois.denic.de"},
59 | {"dk", "whois.dk-hostmaster.dk"},
60 | {"dm", "whois.nic.cx"},
61 | {"dz", "whois.nic.dz"},
62 | {"edu", "whois.educause.net"},
63 | {"ee", "whois.tld.ee"},
64 | {"eg", "whois.ripe.net"},
65 | {"es", "whois.nic.es"},
66 | {"eu", "whois.eu"},
67 | {"eu.com", "whois.centralnic.com"},
68 | {"fi", "whois.ficora.fi"},
69 | {"fo", "whois.nic.fo"},
70 | {"fr", "whois.nic.fr"},
71 | {"gb", "whois.ripe.net"},
72 | {"gb.com", "whois.centralnic.com"},
73 | {"gb.net", "whois.centralnic.com"},
74 | {"qc.com", "whois.centralnic.com"},
75 | {"ge", "whois.ripe.net"},
76 | {"gl", "whois.nic.gl"},
77 | {"gm", "whois.ripe.net"},
78 | {"gov", "whois.nic.gov"},
79 | {"gr", "whois.ripe.net"},
80 | {"gs", "whois.nic.gs"},
81 | {"hk", "whois.hknic.net.hk"},
82 | {"hm", "whois.registry.hm"},
83 | {"hn", "whois2.afilias-grs.net"},
84 | {"hr", "whois.dns.hr"},
85 | {"hu", "whois.nic.hu"},
86 | {"hu.com", "whois.centralnic.com"},
87 | {"id", "whois.pandi.or.id"},
88 | {"ie", "whois.domainregistry.ie"},
89 | {"il", "whois.isoc.org.il"},
90 | {"in", "whois.inregistry.net"},
91 | {"info", "whois.afilias.info"},
92 | {"int", "whois.isi.edu"},
93 | {"io", "whois.nic.io"},
94 | {"iq", "vrx.net"},
95 | {"ir", "whois.nic.ir"},
96 | {"is", "whois.isnic.is"},
97 | {"it", "whois.nic.it"},
98 | {"je", "whois.je"},
99 | {"jobs", "jobswhois.verisign-grs.com"},
100 | {"jp", "whois.jprs.jp"},
101 | {"ke", "whois.kenic.or.ke"},
102 | {"kg", "whois.domain.kg"},
103 | {"kr", "whois.nic.or.kr"},
104 | {"la", "whois2.afilias-grs.net"},
105 | {"li", "whois.nic.li"},
106 | {"lt", "whois.domreg.lt"},
107 | {"lu", "whois.restena.lu"},
108 | {"lv", "whois.nic.lv"},
109 | {"ly", "whois.lydomains.com"},
110 | {"ma", "whois.iam.net.ma"},
111 | {"mc", "whois.ripe.net"},
112 | {"md", "whois.nic.md"},
113 | {"me", "whois.nic.me"},
114 | {"mil", "whois.nic.mil"},
115 | {"mk", "whois.ripe.net"},
116 | {"mobi", "whois.dotmobiregistry.net"},
117 | {"ms", "whois.nic.ms"},
118 | {"mt", "whois.ripe.net"},
119 | {"mu", "whois.nic.mu"},
120 | {"mx", "whois.nic.mx"},
121 | {"my", "whois.mynic.net.my"},
122 | {"name", "whois.nic.name"},
123 | {"net", "whois.verisign-grs.com"},
124 | {"nf", "whois.nic.cx"},
125 | {"ng", "whois.nic.net.ng"},
126 | {"nl", "whois.domain-registry.nl"},
127 | {"no", "whois.norid.no"},
128 | {"no.com", "whois.centralnic.com"},
129 | {"nu", "whois.nic.nu"},
130 | {"nz", "whois.srs.net.nz"},
131 | {"org", "whois.pir.org"},
132 | {"pl", "whois.dns.pl"},
133 | {"pr", "whois.nic.pr"},
134 | {"pro", "whois.registrypro.pro"},
135 | {"pt", "whois.dns.pt"},
136 | {"pw", "whois.nic.pw"},
137 | {"ro", "whois.rotld.ro"},
138 | {"ru", "whois.tcinet.ru"},
139 | {"sa", "saudinic.net.sa"},
140 | {"sa.com", "whois.centralnic.com"},
141 | {"sb", "whois.nic.net.sb"},
142 | {"sc", "whois2.afilias-grs.net"},
143 | {"se", "whois.nic-se.se"},
144 | {"se.com", "whois.centralnic.com"},
145 | {"se.net", "whois.centralnic.com"},
146 | {"sg", "whois.nic.net.sg"},
147 | {"sh", "whois.nic.sh"},
148 | {"si", "whois.arnes.si"},
149 | {"sk", "whois.sk-nic.sk"},
150 | {"sm", "whois.nic.sm"},
151 | {"st", "whois.nic.st"},
152 | {"so", "whois.nic.so"},
153 | {"su", "whois.tcinet.ru"},
154 | {"tc", "whois.adamsnames.tc"},
155 | {"tel", "whois.nic.tel"},
156 | {"tf", "whois.nic.tf"},
157 | {"th", "whois.thnic.net"},
158 | {"tj", "whois.nic.tj"},
159 | {"tk", "whois.nic.tk"},
160 | {"tl", "whois.domains.tl"},
161 | {"tm", "whois.nic.tm"},
162 | {"tn", "whois.ati.tn"},
163 | {"to", "whois.tonic.to"},
164 | {"tp", "whois.domains.tl"},
165 | {"tr", "whois.nic.tr"},
166 | {"travel", "whois.nic.travel"},
167 | {"tw", "whois.twnic.net.tw"},
168 | {"tv", "whois.nic.tv"},
169 | {"tz", "whois.tznic.or.tz"},
170 | {"ua", "whois.ua"},
171 | {"uk", "whois.nic.uk"},
172 | {"uk.com", "whois.centralnic.com"},
173 | {"uk.net", "whois.centralnic.com"},
174 | {"ac.uk", "whois.ja.net"},
175 | {"gov.uk", "whois.ja.net"},
176 | {"us", "whois.nic.us"},
177 | {"us.com", "whois.centralnic.com"},
178 | {"uy", "nic.uy"},
179 | {"uy.com", "whois.centralnic.com"},
180 | {"uz", "whois.cctld.uz"},
181 | {"va", "whois.ripe.net"},
182 | {"vc", "whois2.afilias-grs.net"},
183 | {"ve", "whois.nic.ve"},
184 | {"vg", "whois.adamsnames.tc"},
185 | {"ws", "whois.website.ws"},
186 | {"xxx", "whois.nic.xxx"},
187 | {"yu", "whois.ripe.net"},
188 | {"za.com", "whois.centralnic.com"}
189 | };
190 |
191 | public static string GetWhoisServerName(string domainName)
192 | {
193 | if (String.IsNullOrWhiteSpace(domainName))
194 | {
195 | throw new ArgumentNullException("domainName", "domainName value cannot be a null, empty or whitespace");
196 | }
197 |
198 | if (domainName.Contains('.') == false)
199 | {
200 | throw new ArgumentException("domainName", "Not a valid domain name");
201 | }
202 |
203 | string tld = GetTLDFromDomainName(domainName);
204 | if (String.IsNullOrWhiteSpace(tld))
205 | {
206 | throw new ArgumentException("domainName", "Not a valid domain name");
207 | }
208 | else
209 | {
210 | tld = tld.Trim();
211 | if (WhoisServerCollection.ContainsKey(tld))
212 | {
213 | return WhoisServerCollection[tld];
214 | }
215 | }
216 |
217 | return null;
218 | }
219 |
220 | public static string GetTLDFromDomainName(string domainName)
221 | {
222 | domainName = domainName.ToLower();
223 | var sortedTldList = GetAvailableTLDNameList().OrderByDescending(t => t.Length).ThenBy(t => t).ToList();
224 | for (int i = 0; i < sortedTldList.Count; i++)
225 | {
226 | if (domainName.EndsWith("." + sortedTldList[i]))
227 | return sortedTldList[i];
228 | }
229 |
230 | return null;
231 | }
232 |
233 | public static IEnumerable GetAvailableTLDNameList()
234 | {
235 | return WhoisServerCollection.Keys;
236 | }
237 | }
238 | }
239 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # DomainTools
2 | Various tools and scripts for accessing and managing domain records like fetching whois information of a domain name.
3 |
4 | Though posted on Github recently, this code was actually written a while back for my blog @ http://coderbuddy.wordpress.com, when I had very little programming experience.
5 |
6 | Due to other things in life, I'm not actively maintaining my blog or this code, if you feel that there is something that should be improved, please feel free to raise a PR, I will try my best to get it merged.
7 |
--------------------------------------------------------------------------------