Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX] ipv6 check if lan #35

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ddns.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ def main():
else:
current_public_ip = DDNSUtils.get_current_public_ip()
if not current_public_ip:
import sys
print('Failed to get current public IP')
sys.exit()
DDNSUtils.err_and_exit("Failed to get current public IP")

for local_record in record_manager.local_record_list:
Expand Down
17 changes: 12 additions & 5 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ def get_current_public_ip(cls):
try:
ret = requests.get("http://members.3322.org/dyndns/getip")
except requests.RequestException as ex:
cls.err("network problem:{0}".format(ex))
print("network problem:{0}".format(ex))
return None

if ret.status_code != requests.codes.ok:
cls.err("Failed to get current public IP: {0}\n{1}" \
print("Failed to get current public IP: {0}\n{1}" \
.format(ret.status_code, ret.content))
return None

Expand All @@ -95,8 +95,12 @@ def get_interface_address(cls, ifname):
def get_interface_ipv6_address(cls, ifname):
import netifaces as ni
try:
ip = ni.ifaddresses(ifname)[ni.AF_INET6][0]['addr']
return ip
for ifcfg in ni.ifaddresses(ifname)[ni.AF_INET6]:
ip = ifcfg['addr']
if ip[:4] != 'fe80':
return ip
cls.err("Can't get ipv6 address from the interface {}".format(ifname))
return None
except KeyError:
cls.err("Can't find the interface {}".format(ifname))
return None
Expand All @@ -119,7 +123,10 @@ def get_dns_resolved_ip(cls, subdomain, domainname):
else:
hostname = "{0}.{1}".format(subdomain, domainname)

ip_addr = socket.gethostbyname(hostname)
try:
ip_addr = socket.gethostbyname(hostname)
except socket_error as ex:
ip_addr = socket.getaddrinfo(hostname, None, socket.AF_INET6)[0][4][0]
except socket_error as ex:
cls.err("DomainRecord[{0}] cannot be resolved because of:{1}" \
.format(hostname, ex))
Expand Down