40 lines
1.0 KiB
C#
40 lines
1.0 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)
|
|
{
|
|
try
|
|
{
|
|
if(args.Count() == 0)
|
|
{
|
|
Console.WriteLine("You must provide an host!");
|
|
Environment.Exit(1);
|
|
}
|
|
string hostname = args[0];
|
|
IPHostEntry hostEntry = Dns.GetHostEntry(hostname);
|
|
|
|
Console.WriteLine($"Host : {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}");
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|