Skip to content

Commit

Permalink
Fix IP address binding when netifaces/psutil are not available
Browse files Browse the repository at this point in the history
  • Loading branch information
uzlonewolf committed Jul 8, 2024
1 parent 2b84315 commit adad4cd
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions tinytuya/scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])

Expand Down Expand Up @@ -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 ):
Expand Down

0 comments on commit adad4cd

Please sign in to comment.