45 lines
1.3 KiB
C#
45 lines
1.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace SharpDNSResolver
|
|
{
|
|
class DNSResolver
|
|
{
|
|
static void Main(string[] args)
|
|
{
|
|
if (args.Count() == 0)
|
|
{
|
|
Console.WriteLine("You must provide at least one host!");
|
|
Console.WriteLine("Usage: <prog.exe> <host1> [<host2> host<n>]");
|
|
Environment.Exit(1);
|
|
}
|
|
|
|
int cpt = 0;
|
|
string hostname;
|
|
IPHostEntry hostEntry;
|
|
for (cpt = 0; cpt < args.Length; cpt++)
|
|
{
|
|
try
|
|
{
|
|
hostname = args[cpt];
|
|
hostEntry = Dns.GetHostEntry(hostname);
|
|
Console.WriteLine($"\nHost : {hostEntry.HostName}");
|
|
Console.WriteLine("Ip address:");
|
|
foreach (IPAddress ipAddress in hostEntry.AddressList)
|
|
{
|
|
Console.WriteLine($" {ipAddress}");
|
|
}
|
|
}
|
|
catch (System.Net.Sockets.SocketException ex)
|
|
{
|
|
Console.WriteLine($"Error : {ex.Message}");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|