refactor: ♻️ 2.0 (#13)

This commit is contained in:
2023-12-13 18:43:53 +08:00
committed by GitHub
parent 247e35484c
commit 19f3405a36
288 changed files with 24348 additions and 2141 deletions

View File

@ -0,0 +1,35 @@
// ReSharper disable ClassNeverInstantiated.Global
using System.Net.NetworkInformation;
using System.Net.Sockets;
namespace Dot.IP;
[Description(nameof(Ln.IP工具))]
[Localization(typeof(Ln))]
internal sealed class Main : ToolBase<Option>
{
private const string _HTTP_BIN_ORG_IP = "http://httpbin.org/ip";
protected override async Task CoreAsync()
{
foreach (var item in NetworkInterface.GetAllNetworkInterfaces()) {
if (item.NetworkInterfaceType != NetworkInterfaceType.Ethernet ||
item.OperationalStatus != OperationalStatus.Up) {
continue;
}
var output = string.Join( //
Environment.NewLine
, item.GetIPProperties()
.UnicastAddresses.Where(x => x.Address.AddressFamily == AddressFamily.InterNetwork)
.Select(x => $"{item.Name}: {x.Address}"));
Console.WriteLine(output);
}
using var http = new HttpClient();
Console.Write($"{Ln.公网IP}: ");
var str = await http.GetStringAsync(_HTTP_BIN_ORG_IP).ConfigureAwait(false);
Console.WriteLine(str);
}
}