-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
239 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,18 @@ | ||
|
||
FROM mcr.microsoft.com/dotnet/core/runtime:3.1 AS final | ||
MAINTAINER sanjusss <[email protected]> | ||
LABEL maintainer="[email protected]" | ||
ENV AKID="access key id" | ||
ENV AKSCT="access key secret" | ||
ENV DOMAIN="my.domain.com" | ||
ENV REDO=300 | ||
ENV TTL=600 | ||
ENV TIMEZONE=8 | ||
ENV TYPE=A,AAAA | ||
ENV CNIPV4=false | ||
ENV WEBHOOK= | ||
ENV CHECKLOCAL=false | ||
ENV IPV4NETS= | ||
ENV IPV6NETS= | ||
WORKDIR /app | ||
COPY ./out . | ||
ENTRYPOINT ["dotnet", "aliyun-ddns.dll"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Net; | ||
using System.Net.NetworkInformation; | ||
using System.Net.Sockets; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace aliyun_ddns.IPGetter | ||
{ | ||
public abstract class BaseLocalIPGetter : IIPGetter | ||
{ | ||
public abstract string Description { get; } | ||
public abstract int Order { get; } | ||
|
||
/// <summary> | ||
/// IP网段字符串。 | ||
/// </summary> | ||
protected abstract string IPNetworks { get; } | ||
|
||
/// <summary> | ||
/// 检查IP信息是否符合要求。 | ||
/// </summary> | ||
/// <param name="info">IP信息</param> | ||
/// <returns>是否符合要求</returns> | ||
protected abstract bool CheckIPAddressInformation(IPAddressInformation info); | ||
|
||
public async Task<string> GetIP() | ||
{ | ||
return await Task.Run(() => | ||
{ | ||
try | ||
{ | ||
var nets = GetIPNetworks(); | ||
string ip = null; | ||
//获取所有网卡信息,返回最后一个地址。 | ||
NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces(); | ||
foreach (NetworkInterface adapter in nics) | ||
{ | ||
try | ||
{ | ||
//获取网络接口信息 | ||
IPInterfaceProperties properties = adapter.GetIPProperties(); | ||
//获取单播地址集 | ||
UnicastIPAddressInformationCollection ips = properties.UnicastAddresses; | ||
foreach (UnicastIPAddressInformation i in ips) | ||
{ | ||
if (CheckIPAddressInformation(i) == false) | ||
{ | ||
continue; | ||
} | ||
|
||
bool success = false; | ||
foreach (var net in nets) | ||
{ | ||
if (net.Contains(i.Address)) | ||
{ | ||
success = true; | ||
break; | ||
} | ||
} | ||
|
||
if (success) | ||
{ | ||
ip = i.Address.ToString(); | ||
} | ||
} | ||
} | ||
catch | ||
{ | ||
continue; | ||
} | ||
} | ||
|
||
return ip; | ||
} | ||
catch | ||
{ | ||
return null; | ||
} | ||
}); | ||
} | ||
|
||
private IEnumerable<IPNetwork> GetIPNetworks() | ||
{ | ||
List<IPNetwork> nets = new List<IPNetwork>(); | ||
string text = IPNetworks; | ||
if (string.IsNullOrEmpty(text) == false) | ||
{ | ||
string[] subs = text.Split(',', StringSplitOptions.RemoveEmptyEntries); | ||
foreach (var i in subs) | ||
{ | ||
if (IPNetwork.TryParse(i, out IPNetwork net)) | ||
{ | ||
nets.Add(net); | ||
} | ||
} | ||
} | ||
|
||
return nets; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Net.NetworkInformation; | ||
using System.Net.Sockets; | ||
using System.Text; | ||
|
||
namespace aliyun_ddns.IPGetter.IPv4Getter | ||
{ | ||
/// <summary> | ||
/// 获取所有网卡信息,返回最后一个IPv6地址。 | ||
/// </summary> | ||
[Ignore] | ||
public sealed class LocalIPv4Getter : BaseLocalIPGetter, IIPv4Getter | ||
{ | ||
public override string Description => "读取网卡IPv4设置"; | ||
|
||
public override int Order => 200; | ||
|
||
protected override string IPNetworks => Options.Instance.IPv4Networks; | ||
|
||
protected override bool CheckIPAddressInformation(IPAddressInformation info) | ||
{ | ||
return info.Address.AddressFamily == AddressFamily.InterNetwork; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.