using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
namespace IPSearch
{
class Program
{
static void Main(string[] args)
{
string www = "";
if (args.Length > 0)
{
www = args[0];
if (string.IsNullOrEmpty(www) || string.IsNullOrWhiteSpace(www))
{
Console.WriteLine("Input is empty!");
www = inputWWW();
}
}
else
{
www = inputWWW();
}
Console.WriteLine("Search...");
while (true)
{
IPAddress[] ipAddresses = null;
try
{
ipAddresses = Dns.GetHostAddresses(formatWWW(www));//Important.
}
catch (System.Exception ex)
{
Console.WriteLine(ex.Message);
www = inputWWW();
continue;
}
foreach (IPAddress ipAddress in ipAddresses)
{
Console.WriteLine(ipAddress.ToString());
}
Console.WriteLine("Search Completed!");
Console.WriteLine("Q:Quit.Other key:Continue.");
www = Console.ReadLine();
if (www.ToUpper().Equals("Q"))
{
break;
}
else
{
www = inputWWW();
}
}
}
private static string inputWWW()
{
Console.WriteLine("Input www");
string www = Console.ReadLine();
if (string.IsNullOrEmpty(www) || string.IsNullOrWhiteSpace(www))
{
Console.WriteLine("Input is empty!If you want to exit,please input Q!");
www = Console.ReadLine();
if (www.ToUpper().Equals("Q"))
{
Environment.Exit(1);
}
www = inputWWW();
}
return www;
}
private static string formatWWW(string www)
{
if (string.IsNullOrEmpty(www) || string.IsNullOrWhiteSpace(www))
{
return "";
}
string newWWW = www.ToUpper().Replace("HTTP://", "");
newWWW = newWWW.Split('/')[0];
return newWWW;
}
}
}