mirror of
https://github.com/nsnail/dot.git
synced 2025-06-19 13:58:16 +08:00
<feat> + ip工具
This commit is contained in:
27
src/IP/Main.cs
Normal file
27
src/IP/Main.cs
Normal 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
4
src/IP/Option.cs
Normal file
@ -0,0 +1,4 @@
|
||||
namespace Dot.IP;
|
||||
|
||||
[Verb("ip", HelpText = nameof(Str.Ip), ResourceType = typeof(Str))]
|
||||
public class Option : IOption { }
|
Reference in New Issue
Block a user