Skip to content

Commit

Permalink
2024-11-24 发布
Browse files Browse the repository at this point in the history
  • Loading branch information
BeardedManZhao committed Nov 24, 2024
1 parent 9f88f55 commit 9e8880d
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 44 deletions.
23 changes: 16 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,11 @@ Use `aliyun --help` for more information.

### 在阿里云的DNS解析创建您要解析的子域 DNS

这里我们可以直接前往 [阿里云 DNS 解析](https://wanwang.aliyun.com/domain/dns) 网页中进行 DNS 解析操作,在其中创建出 `A` 或者 `AAAA` 记录,并指向您的服务器 IP 地址(若您没有 ipv6 可以不指定 AAAA 解析类型)
这里我们可以直接前往 [阿里云 DNS 解析](https://wanwang.aliyun.com/domain/dns) 网页中进行 DNS 解析操作,在其中创建出 `A`
或者 `AAAA` 记录,并指向您的服务器 IP 地址(若您没有 ipv6 可以不指定 AAAA 解析类型)

IP地址的位置可以写服务器当前的 IP 地址,但是也可以写错误的,DDNS 程序会自动的将您的 IP 地址进行更改!只要新增了 DNS 解析记录就可以了
IP地址的位置可以写服务器当前的 IP 地址,但是也可以写错误的,DDNS 程序会自动的将您的 IP 地址进行更改!只要新增了 DNS
解析记录就可以了

## 做为软件使用的 启动方法

Expand Down Expand Up @@ -147,11 +149,12 @@ root@gust-desktop:/opt/app/LyMbl_DDNS_Java# java -jar ./LyMbl_AliyunDDNS_Java.ja
### 添加依赖

```xml
<dependency>
<groupId>io.github.BeardedManZhao</groupId>
<artifactId>LyMbl_AliyunDDNS_Java</artifactId>
<version>2024.11.13</version>
</dependency>

<dependency>
<groupId>io.github.BeardedManZhao</groupId>
<artifactId>LyMbl_AliyunDDNS_Java</artifactId>
<version>2024.11.24</version>
</dependency>
```

### maven 组件包中的 main 函数调用
Expand Down Expand Up @@ -201,3 +204,9 @@ public class Main {
}
}
```

# 更新日志

## 2024-11-24

- 优化了域名解析操作中,日志的打印逻辑!!
Original file line number Diff line number Diff line change
Expand Up @@ -68,25 +68,29 @@ public void initIp() {
final Process exec = Runtime.getRuntime().exec("aliyun alidns DescribeDomainRecords --DomainName " + domain);
try (final InputStream inputStream = exec.getInputStream()) {
final JSONObject jsonObject = JSONObject.parseObject(IOUtils.getStringByStream(inputStream));
jsonObject.getJSONObject("DomainRecords").getJSONArray("Record").forEach(o -> {
if (o instanceof JSONObject && RR.equals(((JSONObject) o).getString("RR"))) {
final JSONObject o1 = (JSONObject) o;
final String value = o1.getString("Value");
logger.info("RR: " + RR + " value: " + value);
switch (o1.getString("Type")) {
case "A":
backIpv4 = value;
ipv4DnsId = o1.getString("RecordId");
logger.info("初始化 ipv4: " + backIpv4);
break;
case "AAAA":
backIpv6 = value;
ipv6DnsId = o1.getString("RecordId");
logger.info("初始化 ipv6: " + backIpv6);
break;
try {
jsonObject.getJSONObject("DomainRecords").getJSONArray("Record").forEach(o -> {
if (o instanceof JSONObject && RR.equals(((JSONObject) o).getString("RR"))) {
final JSONObject o1 = (JSONObject) o;
final String value = o1.getString("Value");
logger.info("RR: " + RR + " value: " + value);
switch (o1.getString("Type")) {
case "A":
backIpv4 = value;
ipv4DnsId = o1.getString("RecordId");
logger.info("初始化 ipv4: " + backIpv4);
break;
case "AAAA":
backIpv6 = value;
ipv6DnsId = o1.getString("RecordId");
logger.info("初始化 ipv6: " + backIpv6);
break;
}
}
}
});
});
} catch (NullPointerException e) {
throw new RuntimeException("解析数据失败!", e);
}
}
} catch (IOException e) {
throw new RuntimeException("初始化失败!", e);
Expand Down Expand Up @@ -140,7 +144,7 @@ public void updateIp(String RR, String type, String recordId, String ip) throws
}
logger.info("DDNS exec result: " + output);
} catch (IOException e) {
e.printStackTrace();
logger.warning("DDNS 执行结果读取 错误,执行结果未知,您可以查看相关错误信息: " + e);
}
});

Expand All @@ -157,7 +161,7 @@ public void updateIp(String RR, String type, String recordId, String ip) throws
logger.warning("DDNS exec error: " + errorOutput);
}
} catch (IOException e) {
e.printStackTrace();
logger.warning("DDNS 执行结果读取 错误,本次执行失败了,您可以查看相关错误信息: " + e);
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ default String getLogo() {

/**
* D DNS 启动函数
*
* @param updateTimeMS 更新时间间隔(MS)
*/
void start(long updateTimeMS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ public static void main(String... args) {
FileHandler fileHandler;
try {
final File file = new File(logDir);
if (!file.exists()){
if (file.mkdirs()){
if (!file.exists()) {
if (file.mkdirs()) {
logger.info("创建日志目录成功!");
}
}
Expand Down
16 changes: 1 addition & 15 deletions src/test/java/Main.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,8 @@
import top.lingyuzhao.lyMbl.ddns.aliyun.AliYunDDnsManager;

import java.util.logging.Logger;

/**
* @author zhao
*/
public class Main {
public static void main(String[] args) {
final Logger test = Logger.getLogger("test");
try (
// 实例化 DDNS 管理器
final AliYunDDnsManager aliYunDDnsManager = new AliYunDDnsManager(
// 传递日志对象 以及域名信息
test, "baidu.com", "www"
)
) {
// 启动 每3600s 检查一次 DNS 信息
aliYunDDnsManager.start(3600000);
}

}
}

0 comments on commit 9e8880d

Please sign in to comment.