bpennypacker / phad

Pi-Hole Alternate Display
GNU General Public License v3.0
75 stars 8 forks source link

socket error #3

Closed pfschel closed 5 years ago

pfschel commented 5 years ago

I am getting a persistent socket error when calling FTL function

packedIP = socket.inet_aton(ip) socket.error: illegal IP address string passed to inet_aton

ip values passed seem normal ipv4 addresses when debugging the script. the installation has worked in initial setup.

bpennypacker commented 5 years ago

Hmm. That's peculiar if it's a valid ip as you indicated. It sounds like there's an invalid character in the string. If you're comfortable debugging it then you might try something along these lines to see exactly what characters in the string:

print ":".join("{:02x}".format(ord(c)) for c in ip)

This should print out the ip address string as a string of hex characters, so if ip is '192.168.12.23' it should print out '31:39:32:2e:31:36:38:2e:31:32:2e:32:33'

The hex for a period is 2e, and 0-9 are 30 to 39 so if you see any values outside of those then something is being included in the ip string that shouldn't be. I wonder if there's an extraneous space or some sort of unprintable character (hex 20 or less).

pfschel commented 5 years ago

Did a bit of inline variable printing, Last ip passed before it crashes is ipv6. inet_aton () translates ipv4. My network is mostly ipv6. When disabling ipv6 on the clients, it works as expected. Not sure yet how to handle, will look into it further in the coming days.

bpennypacker commented 5 years ago

Ah, IPv6 makes sense. I currently only have an IPv4 network. I'll have to think about how to support it...

bpennypacker commented 5 years ago

If it's just the ip2long function that's having issues then something along these lines might work.

def ip2long(ip):
    if ':' in ip: # IPv6
        hi, lo = struct.unpack('!QQ', socket.inet_pton(socket.AF_INET6, ip))
        return (hi << 64) | lo
    else: # IPv4
        packedIP = socket.inet_aton(ip)
        return struct.unpack("!L", packedIP)[0]
pfschel commented 5 years ago

that helped, addr should be the ip variable but is moved the problem down the line to get_public_ip. the hyperlink results from a print statement

get_public_ip() https://diagnostic.opendns.com/myip Traceback (most recent call last): File "./phad", line 978, in data = fetch_data(config) File "./phad", line 751, in fetch_data get_timed_data(config, data) File "./phad", line 412, in get_timed_data d['public_ip'] = get_public_ip(cfg) File "./phad", line 289, in get_public_ip response = requests.get(url) File "/home/pi/.local/lib/python2.7/site-packages/requests/api.py", line 75, in get return request('get', url, params=params, kwargs) File "/home/pi/.local/lib/python2.7/site-packages/requests/api.py", line 60, in request return session.request(method=method, url=url, kwargs) File "/home/pi/.local/lib/python2.7/site-packages/requests/sessions.py", line 533, in request resp = self.send(prep, send_kwargs) File "/home/pi/.local/lib/python2.7/site-packages/requests/sessions.py", line 646, in send r = adapter.send(request, kwargs) File "/home/pi/.local/lib/python2.7/site-packages/requests/adapters.py", line 516, in send raise ConnectionError(e, request=request) requests.exceptions.ConnectionError: HTTPSConnectionPool(host='diagnostic.opendns.com', port=443): Max retries exceeded with url: /myip (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0xb5e7a790>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution',))