Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace Whois
- {
- #region Namespaces
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Net;
- using System.IO;
- using System.Xml;
- using System.Net.Sockets;
- #endregion
- class NicosWhoisTool
- {
- private static FileInfo f;
- static void Main(string[] args)
- {
- Console.Title = "Nicos little Whois-Tool";
- //path to the serverlist:
- var xmlFile = AppDomain.CurrentDomain.BaseDirectory + @"\serverlist.xml";
- //string-array to store the servers:
- string[] output = new string[1024];
- //counter variable:
- int z = 0;
- #region parsing the xml-file
- using (XmlReader reader = XmlReader.Create(File.OpenRead(xmlFile)))
- {
- //reading the xml-file
- while (reader.Read())
- {
- //navigate to the <server> element
- reader.ReadToFollowing("server");
- //opening the first-attribute (host="..."):
- reader.MoveToFirstAttribute();
- //writing the host-value into the array:
- string host = reader.Value;
- output[z] = host; //you could write this also short: output[z] = reader.Value;
- z++;
- }
- }
- #endregion
- Console.WriteLine("Please insert the host/ip that you wanna lookup");
- Console.Write("Host/IP:> ");
- string check = Console.ReadLine();
- for (int i = 0; i < output.Length; i++)
- {
- if (null != output[i])
- {
- try
- {
- Console.WriteLine("Checking {0} on Server: {1}", check, output[i]);
- //check the adress in the whois-databases:
- Console.WriteLine(GetWhois(output[i], check));
- }
- catch (Exception ex)
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine("\tError:\n{0}", ex.Message);
- Console.ForegroundColor = ConsoleColor.Gray;
- }
- }
- else
- break;
- }
- Console.WriteLine("\n\t\tWhois-Request done!");
- Console.ReadLine();
- }
- /// <summary>
- /// Gets the Whois-DB-Information.
- /// </summary>
- /// <param name="whoisSvr">The Whois-Server as <see cref="System.String"/>.</param>
- /// <param name="requestUrl">The request Domainname as <see cref="System.String"/>.</param>
- /// <returns>A <see cref="System.String"/> with all the responses from the Servers.</returns>
- private static string GetWhois(string whoisSvr, string requestUrl)
- {
- StringBuilder strbRes = new StringBuilder();
- TcpClient tcpClientWhois = new TcpClient(whoisSvr, 43); //create client on whois-port 43
- NetworkStream nwStrWhois = tcpClientWhois.GetStream();
- BufferedStream bufStrWhois = new BufferedStream(nwStrWhois);
- StreamWriter streamWriter = new StreamWriter(bufStrWhois);
- streamWriter.WriteLine(requestUrl);
- streamWriter.Flush();
- StreamReader streamReaderReceive = new StreamReader(bufStrWhois);
- while (!streamReaderReceive.EndOfStream)
- {
- strbRes.AppendLine(streamReaderReceive.ReadLine());
- }
- return strbRes.ToString();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement