using System.Net;
namespace ConsoleApp;
internal class Program
{
private const int SUCCESS = 0;
private const int COMMAND_LINE_ARGS_ARE_NOT_SPECIFIED = 1;
private const int EXCEPTION_THROWN = 2;
private static Task<int> Main(string[] args)
{
return new Program().Run(args);
}
private async Task<int> Run(string[] args)
{
if (args.Length == 0)
{
Console.WriteLine("Not enough positional command-line arguments specified!");
return COMMAND_LINE_ARGS_ARE_NOT_SPECIFIED;
}
try
{
foreach (string hostName in args)
{
IPHostEntry hostEntry = await Dns.GetHostEntryAsync(hostName);
DisplayHost(hostEntry);
}
return SUCCESS;
}
catch (Exception ex)
{
Console.WriteLine(ex);
return EXCEPTION_THROWN;
}
}
private void DisplayHost(IPHostEntry hostEntry)
{
Console.WriteLine(hostEntry.HostName);
foreach (var ipAddress in hostEntry.AddressList)
{
Console.WriteLine(ipAddress);
}
Console.WriteLine("---");
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
но в таком случае как читы пишут