risfeng / aliyun-ddns-shell

阿里云域名解析动态更新IP Shell脚本
MIT License
333 stars 102 forks source link

自定义获取wan ip的命令执行起来似乎有些问题? #31

Open int233 opened 1 year ago

int233 commented 1 year ago

在这行https://github.com/risfeng/aliyun-ddns-shell/blob/219ac8e5fcfdc767fe74fce221913d5f839699ca/src/aliyun/aliyun-ddns.sh#L240

我自定义获取wan ip的命令后

curl -s http://ip4.ouc.edu.cn/Default2.aspx | grep '访客IP地址: '  | sed 's/:/\n/g' | sed '1d' | sed 's/</\n/g' | sed '2d' | sed '2d' | sed '1,1 s/^.//g'

运行程序只能得到curl的结果,而不是后面的ip地址,结果附在最后

因此我只能手动改掉这一行,目前可以正常使用

var_local_wan_ip=`curl -s http://ip4.ouc.edu.cn/Default2.aspx | grep '访客IP地址: '  | sed 's/:/\n/g' | sed '1d' | sed 's/</\n/g' | sed '2d' | sed '2d' | sed '1,1 s/^.//g'` 
#var_local_wan_ip=`${var_local_wan_ip}`

附上curl的结果供参考

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>
</title></head>
<body>
    <form method="post" action="./Default2.aspx" id="form1">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="L07yESAT50CeA13U36h4ZrAtKEvwVaTD08lyqE+1H+/MSG9mIdDClItr060ShQ/na1++C44a3iy4Am4h0v9kG4QZDu9nVjl60a8rJkNBv7n0HCMvctexxEtouPdMl9R+Q9IJqq5JM41JYnl8ylzVbdWW2HPY6mndtuAor4t+Qj0=" />
<input type="hidden" name="__VIEWSTATEGENERATOR" id="__VIEWSTATEGENERATOR" value="9BD98A7D" />
    <div>
        <pre id="best-content-2392302861" accuse="aContent" class="best-text mb-10" style="margin: 10px 0px; padding: 0px; font-family: &quot;PingFang SC&quot;, &quot;Lantinghei SC&quot;, &quot;Microsoft YaHei&quot;, arial, 宋体, sans-serif, tahoma; white-space: pre-wrap; word-wrap: break-word; font-size: 16px; line-height: 29px; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-style: initial; text-decoration-color: initial; min-height: 55px;"><span id="Label1">访客IP地址: 10.190.10.125</span></pre>
    </div>
    </form>
</body>
</html>

原版程序的运行结果

root@***-145VM:~# sh /mnt/sdb1/App/aliddns/aliyun-ddns.sh -run
=========== 2022年 11月 23日 星期三 21:03:59 CST ===========

#############################################################
# Aliyun Domain DNS Update Shell Script
#
# Dynamic DNS Update Using Aliyun API
#
# Version: v1.0.0
# BuildDate: 20200307
# Author: risfeng<risfeng@gmail.com>
# GitHub: https://github.com/risfeng/aliyun-ddns-shell
#
# Usage: please refer to https://github.com/risfeng/aliyun-ddns-shell/blob/master/README.md
#
#############################################################

[Info]    2022-11-23 21:03:59 检测到配置文件,自动加载现有配置信息。可通过菜单选项【恢复出厂设置】重置.
[Info]    2022-11-23 21:03:59 正在尝试检测外网:ping www.baidu.com 1 times......
[Success] 2022-11-23 21:03:59 检测外网成功!
[Info]    2022-11-23 21:03:59 正在获取本机外网ip......
[Info]    2022-11-23 21:03:59 本机外网ip:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>
</title></head>
<body>
    <form method="post" action="./Default2.aspx" id="form1">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="0qnytskylSD8Vy2l2Oa8+l96+6Myq4GX071uGNeVqOJBb1RYCnyLqYcqmqDEBpsb0W1fHltE8CSVKjEZZ7Ruy07S6vsuYBboFn2lbh29t77HgLAOrbAkIqBQbAdvGVBp0zp+u8iX5HXzE7xpf1xYRTolbuzzQ3ZOuNxesJpl5HM=" />
<input type="hidden" name="__VIEWSTATEGENERATOR" id="__VIEWSTATEGENERATOR" value="9BD98A7D" />
    <div>
        <pre id="best-content-2392302861" accuse="aContent" class="best-text mb-10" style="margin: 10px 0px; padding: 0px; font-family: &quot;PingFang SC&quot;, &quot;Lantinghei SC&quot;, &quot;Microsoft YaHei&quot;, arial, 宋体, sans-serif, tahoma; white-space: pre-wrap; word-wrap: break-word; font-size: 16px; line-height: 29px; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-style: initial; text-decoration-color: initial; min-height: 55px;"><span id="Label1">访客IP地址: 10.190.10.125</span></pre>
    </div>
    </form>
</body>
</html>
[Info]    2022-11-23 21:03:59 正在获取******的ip......
[Info]    2022-11-23 21:03:59 域名******的当前ip:
[Info]    2022-11-23 21:03:59 正在更新域名解析记录值......
[Info]    2022-11-23 21:03:59 正在获取record_id......
[Info]    2022-11-23 21:03:59 获取到到record_id=797644783185760256
[Info]    2022-11-23 21:03:59 正在更新解析记录:[******]的ip为[
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>
</title></head>
<body>
    <form method="post" action="./Default2.aspx" id="form1">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="0qnytskylSD8Vy2l2Oa8+l96+6Myq4GX071uGNeVqOJBb1RYCnyLqYcqmqDEBpsb0W1fHltE8CSVKjEZZ7Ruy07S6vsuYBboFn2lbh29t77HgLAOrbAkIqBQbAdvGVBp0zp+u8iX5HXzE7xpf1xYRTolbuzzQ3ZOuNxesJpl5HM=" />
<input type="hidden" name="__VIEWSTATEGENERATOR" id="__VIEWSTATEGENERATOR" value="9BD98A7D" />
    <div>
        <pre id="best-content-2392302861" accuse="aContent" class="best-text mb-10" style="margin: 10px 0px; padding: 0px; font-family: &quot;PingFang SC&quot;, &quot;Lantinghei SC&quot;, &quot;Microsoft YaHei&quot;, arial, 宋体, sans-serif, tahoma; white-space: pre-wrap; word-wrap: break-word; font-size: 16px; line-height: 29px; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-style: initial; text-decoration-color: initial; min-height: 55px;"><span id="Label1">访客IP地址: 10.190.10.125</span></pre>
    </div>
    </form>
</body>
]......
[Info]    2022-11-23 21:03:59 已经更新record_id=797644783185760256的记录
[Success] 2022-11-23 21:03:59 域名[******](新IP:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>
</title></head>
<body>
    <form method="post" action="./Default2.aspx" id="form1">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="0qnytskylSD8Vy2l2Oa8+l96+6Myq4GX071uGNeVqOJBb1RYCnyLqYcqmqDEBpsb0W1fHltE8CSVKjEZZ7Ruy07S6vsuYBboFn2lbh29t77HgLAOrbAkIqBQbAdvGVBp0zp+u8iX5HXzE7xpf1xYRTolbuzzQ3ZOuNxesJpl5HM=" />
<input type="hidden" name="__VIEWSTATEGENERATOR" id="__VIEWSTATEGENERATOR" value="9BD98A7D" />
    <div>
        <pre id="best-content-2392302861" accuse="aContent" class="best-text mb-10" style="margin: 10px 0px; padding: 0px; font-family: &quot;PingFang SC&quot;, &quot;Lantinghei SC&quot;, &quot;Microsoft YaHei&quot;, arial, 宋体, sans-serif, tahoma; white-space: pre-wrap; word-wrap: break-word; font-size: 16px; line-height: 29px; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-style: initial; text-decoration-color: initial; min-height: 55px;"><span id="Label1">访客IP地址: 10.190.10.125</span></pre>
    </div>
    </form>
</body>
)记录更新成功。
jilefo commented 1 year ago

改成 curl ifconfig.co