NewFuture / DDNS

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

[debug]取本地ipv6地址时出错 #387

Open ghost opened 1 year ago

ghost commented 1 year ago

描述问题 (Describe the bug)

取本地ipv6地址时出错,想要直接取本地网卡(ens33)的ipv6地址(光猫直接分配的),在getaddrinfo时出错。

版本信息 (version info)

复现步骤 (To Reproduce)

配置config.json,执行ddns -c config.json ip addr 执行显示ens33是第二个网卡

配置文件 (config file)

config.json { "token": "xxxxxxxxxxxxxx", "dns": "cloudflare", "ipv4": [], "ipv6": ["xxx.yyyyy.com"], "index6": 1, "debug": true }

调试输出 (debug output)

Traceback (most recent call last): File "/usr/local/bin/ddns", line 8, in sys.exit(main()) File "/usr/local/lib/python3.8/dist-packages/run.py", line 151, in main update_ip('6', cache, dns, proxy_list) File "/usr/local/lib/python3.8/dist-packages/run.py", line 97, in update_ip address = get_ip(ip_type, index_rule) File "/usr/local/lib/python3.8/dist-packages/run.py", line 51, in get_ip value = getattr(ip, "local_v" + ip_type)(index) File "/usr/local/lib/python3.8/dist-packages/util/ip.py", line 38, in local_v6 info = getaddrinfo(gethostname(), 0, AF_INET6) File "/usr/lib/python3.8/socket.py", line 918, in getaddrinfo for res in _socket.getaddrinfo(host, port, family, type, proto, flags): socket.gaierror: [Errno -5] No address associated with hostname

补充说明 (Additional context)

/etc/hosts中配置为127.0.1.1 ubuntu 手动执行getaddrinfo(gethostname(), 0, AF_INET)时返回的是127.0.0.1,好像ipv4也没有达到获取某网卡地址的功能,这个功能原想法应该不是想要获取lo回环地址吧?

现在暂时用default方式实现的。

ghostLiulang commented 4 months ago

我是使用shell的形式进行获取ipv6地址 "index6": "shell: /usr/sbin/ifconfig eth0 | egrep -o '24.*:.*:[a-z0-9]{3,4}:[a-z0-9]{3,4}' | head -n 1", 这段代码在树莓派4B (基于debian 12)上是可以运行的.