Closed pfschel closed 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).
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.
Ah, IPv6 makes sense. I currently only have an IPv4 network. I'll have to think about how to support it...
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]
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
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.