• 极路由4pro(HC5962)设置阿里云DDNS


    v2ex有个帖子说用Dnspod的API可以一行搞定,不过我既然买的是阿里云的域名还是想尽量用阿里云的API,感觉比较安全,另外修改解析记录后也会自动发邮件通知,所以还是调用阿里云的API吧。阿里云的API需要做加密工作,用shell反而不太好写,还是用java写吧。

    阿里云官方java SDK

    如果用java6、7、8的话,还是直接用官方的SDK比较方便:
    maven依赖:

            <dependency>
                <groupId>com.aliyun</groupId>
                <artifactId>aliyun-java-sdk-core</artifactId>
                <version>2.4.4</version>
            </dependency>
    
            <dependency>
                <groupId>com.aliyun</groupId>
                <artifactId>aliyun-java-sdk-alidns</artifactId>
                <version>2.0.6</version>
            </dependency>
    

    maven仓库:

         <repositories>
    		<repository>
    			<id>sonatype-nexus-staging</id>
    			<name>Sonatype Nexus Staging</name>
    			<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
    			<releases>
    				<enabled>true</enabled>
    			</releases>
    			<snapshots>
    				<enabled>true</enabled>
    			</snapshots>
    		</repository>
    	</repositories>
    

    然后几句java代码即可操作DNS解析:

            DefaultProfile profile = DefaultProfile.getProfile("<regionId>", "<accessKeyId>", "<secret>");
            DefaultAcsClient client = new DefaultAcsClient(profile);
    
             // 获取域名解析列表
            DescribeDomainRecordsRequest request = new DescribeDomainRecordsRequest();
            request.setDomainName(domainName);  // 写你的域名,例如xxx.com
            DescribeDomainRecordsResponse domainRecordsResponse = client.getAcsResponse(request);
            List<DescribeDomainRecordsResponse.Record> domainRecords = domainRecordsResponse .getDomainRecords();
    
            // 获取第一个域名解析记录,假设是A记录
            DescribeDomainRecordsResponse.Record record = domainRecords.get(0);
         
            // 修改DNS解析记录
            UpdateDomainRecordRequest request = new UpdateDomainRecordRequest();
            request.setRecordId(record.getRecordId());
            request.setRR(record.getRR());
            request.setType(record.getType());
            request.setValue(ip);  // 修改为路由器的ip
            acsClient.getAcsResponse(request);
    

    极路由设置阿里云DDNS

    但是没办法啊,mipsel架构上只能装jamvm用java 1.5,jamvm安装教程在这里:极路由安装java教程
    改官方源码也比较麻烦,因为它也有maven依赖,这些依赖包也是java6以上的,要改源码的话连依赖包也得改,更麻烦。

    那没办法,只能看一下阿里云SDK的源码,然后用java1.5重写一套精简的咯。

    使用教程和代码参见github: aliyun_ddns

    免编译jar包下载:

    链接:https://pan.baidu.com/s/1ggiedEz 密码:ptpg
    

    运行这个jar包后,如果域名解析记录和公网ip不一样则会自动修改域名解析记录的值为公网ip:

  • 相关阅读:
    Redis安装测试
    linux 查看磁盘空间大小
    冷备份与热备份、双机热备与容错
    IDEA在编辑时提示could not autowire
    IntelliJ IDEA 快捷键和设置
    POI实现EXCEL单元格合并及边框样式
    metaq架构原理
    二叉树
    开启“树”之旅
    巧妙的邻接表(数组实现)
  • 原文地址:https://www.cnblogs.com/lanhj/p/8250435.html
Copyright © 2020-2023  润新知