In the environment of CERNET2, 2001:4860:4860::8888 and 2001:4860:4860::8844 are actually blocked. So the old update_hosts.py cannot work correctly in China.
Using https://dns.google.com/resolve . I also give some examples of using cloudflare dns or quad9 dns in comment. In case google dns is blocked, users can modify their .py file by themselves. However, EDNS feature is not support by cloudflare or quad9.
Adding TCP connectivity function that used for detecting whether IP is blocked by GFW. If it is blocked, try again until finding a accessable ip or reaching the limit.
Using different edns_client_subnet ip that belongs to HK,TW,SG,JP,KR,USA, in order to get more ip address.
To those who using devices with small rom like openwrt router, simplifying hosts.out will be useful.
Using set() function to cache the TCP connectivity detection result. So that the running time will decrease.
As IPV4 address has been blocked completely, we don't need ipv4 addresses in hosts. So the best solution is to separate the hosts_ipv4 and hosts_ipv6. If someone wants to using ipv4 hosts, then there is a choice for him.
The changes
In the environment of CERNET2,
2001:4860:4860::8888
and2001:4860:4860::8844
are actually blocked. So the old update_hosts.py cannot work correctly in China.https://dns.google.com/resolve
. I also give some examples of using cloudflare dns or quad9 dns in comment. In case google dns is blocked, users can modify their .py file by themselves. However, EDNS feature is not support by cloudflare or quad9.As IPV4 address has been blocked completely, we don't need ipv4 addresses in hosts. So the best solution is to separate the hosts_ipv4 and hosts_ipv6. If someone wants to using ipv4 hosts, then there is a choice for him.
我是一个计算机技术的门外汉,正在自学python,所以写的不好也请见谅。因为我自己也需要用,然后也挺感兴趣就改了您的代码。有些冗余的代码实际上是可以删除的,但是我比较懒也没删掉。比如实际上已经不使用dig命令了,那么对dig是否安装的检测也就没有必要。