diff --git a/tinytuya/scanner.py b/tinytuya/scanner.py index 2f5ed54..75e600e 100644 --- a/tinytuya/scanner.py +++ b/tinytuya/scanner.py @@ -96,13 +96,16 @@ log = logging.getLogger(__name__) # Helper Functions -def getmyIP(): +def getmyIPaddr(): # Fetch my IP address and assume /24 network s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.connect(("8.8.8.8", 80)) - r = s.getsockname()[0] + r = str(s.getsockname()[0]) s.close() - r = str(r).split('.') + return r + +def getmyIP(): + r = getmyIPaddr().split('.') # assume a /24 network return '%s.%s.%s.0/24' % tuple(r[:3]) @@ -196,7 +199,7 @@ def get_ip_to_broadcast(): if ip_to_broadcast: return ip_to_broadcast - ip_to_broadcast['255.255.255.255'] = getmyIP() + ip_to_broadcast['255.255.255.255'] = getmyIPaddr() return ip_to_broadcast def send_discovery_request( iface_list=None ):