* <feat> + ip工具
This commit is contained in:
nsnail 2022-12-05 17:36:51 +08:00 committed by GitHub
parent deebd018f4
commit 2efc7ac76e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 70 additions and 3 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 { }

View File

@ -122,6 +122,15 @@ namespace Dot.Lang {
}
}
/// <summary>
/// Looks up a localized string similar to IP工具.
/// </summary>
public static string Ip {
get {
return ResourceManager.GetString("Ip", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Local clock offset.
/// </summary>
@ -203,6 +212,15 @@ namespace Dot.Lang {
}
}
/// <summary>
/// Looks up a localized string similar to Public network ip... .
/// </summary>
public static string PublicIP {
get {
return ResourceManager.GetString("PublicIP", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to BitSet 1[0-9]2[a-z]4[A-Z]8[ascii.0x21-0x2F].
/// </summary>
@ -285,7 +303,7 @@ namespace Dot.Lang {
}
/// <summary>
/// Looks up a localized string similar to NTP 标准网络时钟: {0}.
/// Looks up a localized string similar to 同步本机时间.
/// </summary>
public static string ServerTime {
get {

View File

@ -122,4 +122,13 @@
<data name="ClickCopyColor" xml:space="preserve">
<value>Click the left mouse button to copy the colors and coordinates to the clipboard</value>
</data>
<data name="PublicIP" xml:space="preserve">
<value>Public network ip: </value>
</data>
<data name="ServerTime" xml:space="preserve">
<value>Synchronize local time</value>
</data>
<data name="Ip" xml:space="preserve">
<value>IP tools</value>
</data>
</root>

View File

@ -42,6 +42,9 @@
<data name="TimeTool" xml:space="preserve">
<value>时间同步工具</value>
</data>
<data name="Ip" xml:space="preserve">
<value>IP工具</value>
</data>
<data name="ScreenPixelTool" xml:space="preserve">
<value>屏幕坐标颜色选取工具</value>
</data>
@ -63,7 +66,9 @@
<data name="SyncToLocalTime" xml:space="preserve">
<value>同步本机时间</value>
</data>
<data name="ServerTime" xml:space="preserve">
<value>同步本机时间</value>
</data>
<data name="FolderPath" xml:space="preserve">
<value>要处理的目录路径</value>
</data>
@ -131,4 +136,7 @@
<data name="ClickCopyColor" xml:space="preserve">
<value>单击鼠标左键复制颜色和坐标到剪贴板</value>
</data>
<data name="PublicIP" xml:space="preserve">
<value>Public network ip... </value>
</data>
</root>

View File

@ -15,6 +15,7 @@ public static class ToolsFactory
, Guid.Option o => new Guid.Main(o)
, Time.Option o => new Time.Main(o)
, Color.Option o => new Color.Main(o)
, IP.Option o => new IP.Main(o)
, _ => throw new ArgumentOutOfRangeException(nameof(option))
};
}

View File

@ -7,7 +7,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<RootNamespace>Dot</RootNamespace>
<AssemblyName>dot</AssemblyName>
<Version>1.1.2</Version>
<Version>1.1.3</Version>
<Authors>nsnail</Authors>
<Copyright>Copyright (c) 2022 nsnail</Copyright>
<RepositoryUrl>https://github.com/nsnail/dot.git</RepositoryUrl>