<feat> + ip工具

This commit is contained in:
2022-12-05 17:34:45 +08:00
parent 5678fa68cb
commit c4448ad7b2
6 changed files with 69 additions and 2 deletions

27
src/IP/Main.cs Normal file
View File

@ -0,0 +1,27 @@
using System.Net.NetworkInformation;
using System.Net.Sockets;
namespace Dot.IP;
public sealed class Main : Tool<Option>
{
public Main(Option opt) : base(opt) { }
public override async Task Run()
{
foreach (var item in NetworkInterface.GetAllNetworkInterfaces()) {
if (item.NetworkInterfaceType != NetworkInterfaceType.Ethernet ||
item.OperationalStatus != OperationalStatus.Up)
continue;
foreach (var ip in item.GetIPProperties().UnicastAddresses)
if (ip.Address.AddressFamily == AddressFamily.InterNetwork)
Console.WriteLine(@$"{item.Name}: {ip.Address}");
}
using var http = new HttpClient();
Console.Write(Str.PublicIP);
var str = await http.GetStringAsync("http://httpbin.org/ip");
Console.WriteLine(str);
}
}

4
src/IP/Option.cs Normal file
View File

@ -0,0 +1,4 @@
namespace Dot.IP;
[Verb("ip", HelpText = nameof(Str.Ip), ResourceType = typeof(Str))]
public class Option : IOption { }