NewFuture / DDNS

:triangular_flag_on_post: 自动更新域名解析到本机IP(支持dnspod,阿里DNS,CloudFlare,华为云,DNSCOM...)
https://ddns.newfuture.cc/
MIT License
4.31k stars 657 forks source link

[debug] public_v4 方法返回错误的ipv4地址 #367

Closed pg-adm1n closed 1 year ago

pg-adm1n commented 1 year ago

描述问题 (Describe the bug)

根据源码 https://github.com/NewFuture/DDNS/blob/3680c2088c9d8a6d6bae97540cb5714ae4a2416a/util/ip.py#L61 获取ipv4地址是通过访问 https://pv.sohu.com/cityjson?ie=utf-8, 但是目前这个接口返回了错误的ipv4地址, 一直显示上海, 是因为这个域名被指向了某些LB导致的吗? 我查看过返回的IP, 在IPIP显示是 IDC地址段

版本信息 (version info)

复现步骤 (To Reproduce)

访问 https://pv.sohu.com/cityjson?ie=utf-8

var returnCitySN = {"cip": "61.151.164.141", "cid": "310000", "cname": "上海市"};

配置文件 (config file)

{
}

调试输出 (debug output)

粘贴输出日志
paste out put here

补充说明 (Additional context)

pg-adm1n commented 1 year ago

需要改到 https://myip4.ipip.net, https://ddns.oray.com/checkip, https://ip.3322.net ??

gitLinan commented 1 year ago

北京电信也遇到了这个问题,很大一部分时间是403,正常请求返回的ip不对

2022-11-25 13:15:00,892 <ip._open> 51@util/ip.py 
[DEBUG] open: https://pv.sohu.com/cityjson?ie=utf-8 2022-11-25 13:15:01,093 <ip._open> 58@util/ip.py 
[ERROR] HTTP Error 403: Forbidden 
2022-11-25 13:15:01,094 <run.update_ip> 100@run.py 
[ERROR] Fail to get ipv4 address!

我是北京的,解析的结果是天津

2022-11-25 13:25:01,083 <ip._open> 55@util/ip.py 
[DEBUG] response: var returnCitySN = {"cip": "123.151.77.28", "cid": "120000", "cname": "天津市"};
Xiaye2332 commented 1 year ago

同样出现了这个问题,解析结果一直是上海的。

bilibililingling commented 1 year ago

同样出现这个问题 解析结果是上海的

yeunglee commented 1 year ago

1)建议 获取ip地址的URL可以从config文件配置(不要hardcode) 我之前用的是旧版,现在最新的版本中,配置文件里的index4index6 就已经支持了 2)建议 可以从多个源获取ip地址,当获取到的相同ip地址多于一半时(或者一定比例),才采用

bilibililingling commented 1 year ago

谢谢 我会去尝试您给出的多个建议 没有问题的话 我希望我可以把您的建议发布到issue里

------------------ 原始邮件 ------------------ 发件人: @.>; 发送时间: 2022年11月26日(星期六) 上午10:07 收件人: @.>; 抄送: @.>; @.>; 主题: Re: [NewFuture/DDNS] [debug] public_v4 方法返回错误的ipv4地址 (Issue #367)

1)建议 获取ip地址的URL可以从config文件配置(不要hardcode) 2)建议 可以从多个源获取ip地址,当获取到的相同ip地址多于一半时(或者一定比例),才采用

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>

xdxiaodong commented 1 year ago

我这边是不停的获取到错误的IPV4地址,原因是https://pv.sohu.com/cityjson?ie=utf-8返回403,建议增加备用获取IP的网址

yeunglee commented 1 year ago

有这个问题的,可以修改config.json配置文件:

{
...
  "index4": "url:https://ddns.oray.com/checkip",
...
}

或者选择其他适合获取ip的URL: https://myip4.ipip.net/, https://ddns.oray.com/checkip, https://ip.3322.net/

我使用的是最新版本

bilibililingling commented 1 year ago

我测试了 搜狐的回调出现了问题 可以尝试更换api

bilibililingling commented 1 year ago

url:https://ddns.oray.com/checkip

测试了 可以的 通过这个地址信息回调也是可以的 按照现在的情况,预估大多没有更改config.json文件index选项的都会出现问题,大家可以尝试按照这个方法重新调整

pg-adm1n commented 1 year ago

https://ip.3322.net/ 那倒不如直接用这个吧

pg-adm1n commented 1 year ago

已解决 "index4": "url:https://ip.3322.net",

yeunglee commented 1 year ago

https://ip.3322.net/ 那倒不如直接用这个吧

显然是选择一个名气大的网站,稳定性会更好。有些小网站,用的人多了,就把接口封了

ikichen commented 1 year ago

ERROR:root:<urlopen error [Errno -3] Try again> ERROR:root:Fail to get ipv4 address!

我也遇到了这个问题,该怎么修改获取ip的方式?

InDimension commented 1 year ago

老哥们,public的返回403了 目前修改config中 ipv4使用了 url:https://myip4.ipip.net/ ipv6使用了 url:https://myip6.ipip.net/

Xiaye2332 commented 1 year ago

简易解决办法 源码DDNS/util/ip.py Line 61

def public_v4(url="https://pv.sohu.com/cityjson?ie=utf-8", reg=IPV4_REG): # 公网IPV4地址

将其中url字段更改为https://ip.3322.net/

wangyw6716 commented 1 year ago

有这个问题的,可以修改config.json配置文件:

{
...
  "index4": "url:https://ddns.oray.com/checkip",
...
}

或者选择其他适合获取ip的URL:https://myip4.ipip.net/,https://ddns.oray.com/checkip,https://ip.3322.net/

我使用的是最新版本

感谢, 已解决

RunawayFancy commented 1 year ago

同时向多个地址获取ipv4,判断重复最多的ipv4为真,并返回不对的ipv4

NewFuture commented 1 year ago

更新了