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

Fix scanner force-scanning #511

Merged
merged 25 commits into from
Jul 8, 2024
Merged
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
d3be0ac
Fix scanner force-scanning
uzlonewolf Jun 23, 2024
d3bc3d0
Allow a string as the force-scan list
uzlonewolf Jun 23, 2024
d088823
Add force-scanning v3.5 devices to scanner
uzlonewolf Jun 23, 2024
e9fd881
Add force-scanning v3.5 devices to scanner
uzlonewolf Jun 23, 2024
0690e8c
v1.14.2 Notes
jasonacox Jun 23, 2024
7259b8d
Rename scanner variable try_v35 to a more descriptive try_v35_with_v34
uzlonewolf Jun 24, 2024
9420ec6
Make sure set_version() is given a float (#507)
uzlonewolf Jun 24, 2024
133fd35
Allow host bits in the force-scan network list
uzlonewolf Jun 25, 2024
da6d01b
Refactor _print_device_info function to include verbose flag
jasonacox Jun 25, 2024
51f7653
Merge branch 'forcescan-fix' of https://github.com/uzlonewolf/tinytuy…
jasonacox Jun 25, 2024
7d160a0
Allow device discovery packets on port 7000
uzlonewolf Jul 7, 2024
ff6abf2
Add get_ip_to_broadcast() function to scanner
uzlonewolf Jul 7, 2024
5f38b49
Add "Force Scan" button and UI updates
jasonacox Jul 7, 2024
59a013f
Merge branch 'forcescan-fix' of https://github.com/uzlonewolf/tinytuy…
jasonacox Jul 7, 2024
831f113
Make scanner send broadcasts to port 7000
uzlonewolf Jul 7, 2024
4d46538
Update control panel image
jasonacox Jul 7, 2024
6073a8c
Add port 7000 support to tools/pcap_parse.py
uzlonewolf Jul 7, 2024
3610184
Merge branch 'forcescan-fix' of github-lw:uzlonewolf/tinytuya into fo…
uzlonewolf Jul 7, 2024
a20b080
Fix incorrect message log level
uzlonewolf Jul 7, 2024
2fbb691
Allow calling send_discovery_request() without an argument
uzlonewolf Jul 7, 2024
0b19990
Rewrite tinytuya.find_device() to use the scanner
uzlonewolf Jul 7, 2024
c6dba30
Also use psutil to get the force-scan IP list if netifaces is not ava…
uzlonewolf Jul 7, 2024
b00882a
Close the broadcast sockets once we're done with them
uzlonewolf Jul 7, 2024
728779d
Add broadcast for 3.5 devices to server
jasonacox Jul 7, 2024
3aea261
Release notes
jasonacox Jul 8, 2024
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
20 changes: 12 additions & 8 deletions tinytuya/scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ def stop( self ):
self.deviceinfo['version'] = 0.0

if self.options['verbose'] and self.found and not self.displayed:
_print_device_info( self.deviceinfo, 'Failed to Force-Scan, FORCED STOP', self.options['termcolors'], self.message )
_print_device_info( self.deviceinfo, 'Failed to Force-Scan, FORCED STOP', self.options['termcolors'], self.message, self.options['verbose'] )
self.displayed = True

def timeout( self, forced=False ):
Expand Down Expand Up @@ -385,7 +385,7 @@ def timeout( self, forced=False ):
self.err_found = True
self.deviceinfo['version'] = 0.0
self.message = "%s Polling %s Failed: Device stopped responding before key was found" % (self.options['termcolors'].alertdim, self.ip)
_print_device_info( self.deviceinfo, 'Failed to Force-Scan', self.options['termcolors'], self.message )
_print_device_info( self.deviceinfo, 'Failed to Force-Scan', self.options['termcolors'], self.message, self.options['verbose'])
self.displayed = True
self.close()
return
Expand All @@ -398,7 +398,7 @@ def timeout( self, forced=False ):
elif forced:
self.err_found = True
self.message = "%s Polling %s Failed: Unexpected close during read/write operation" % (self.options['termcolors'].alertdim, self.ip)
_print_device_info( self.deviceinfo, 'Failed to Force-Scan', self.options['termcolors'], self.message )
_print_device_info( self.deviceinfo, 'Failed to Force-Scan', self.options['termcolors'], self.message, self.options['verbose'])
self.displayed = True
self.remove = True
elif self.step == FSCAN_v31_PASSIVE_LISTEN or self.step == FSCAN_v33_BRUTE_FORCE_ACQUIRE:
Expand All @@ -409,14 +409,14 @@ def timeout( self, forced=False ):
elif self.step == FSCAN_FINAL_POLL:
if not self.message:
self.message = "%s Polling %s Failed: No response to poll request" % (self.options['termcolors'].alertdim, self.ip)
_print_device_info( self.deviceinfo, 'Force-Scanned', self.options['termcolors'], self.message )
_print_device_info( self.deviceinfo, 'Force-Scanned', self.options['termcolors'], self.message, self.options['verbose'])
self.displayed = True
self.remove = True
else:
if self.debug:
print('ForceScannedDevice: Debug sock', self.ip, 'timeout on unhandled step', self.step)
self.remove = True
_print_device_info( self.deviceinfo, 'Failed to Force-Scan', self.options['termcolors'], self.message )
_print_device_info( self.deviceinfo, 'Failed to Force-Scan', self.options['termcolors'], self.message, self.options['verbose'])
self.displayed = True

if self.remove:
Expand Down Expand Up @@ -723,7 +723,7 @@ def v3x_brute_force_try_next_key( self ):
self.remove = True
self.deviceinfo['version'] = 0.0
self.message = "%s Polling %s Failed: No matching key found" % (self.options['termcolors'].alertdim, self.ip)
_print_device_info( self.deviceinfo, 'Failed to Force-Scan', self.options['termcolors'], self.message )
_print_device_info( self.deviceinfo, 'Failed to Force-Scan', self.options['termcolors'], self.message, self.options['verbose'] )
self.displayed = True
else:
if self.debug:
Expand Down Expand Up @@ -944,7 +944,9 @@ def _generate_ip(networks, verbose, term):
for addr in ipaddress.IPv4Network(network):
yield str(addr)

def _print_device_info( result, note, term, extra_message=None ):
def _print_device_info( result, note, term, extra_message=None, verbose=True ):
if not verbose:
return
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed while testing that verbose=False was not honored.

scanner.devices(verbose=False, color=False, poll=False, forcescan="10.0.0.0/24",discover=False)

Printed all the devices. I updated scanner to ignore prints if verbose=False.

ip = result["ip"]
gwId = result["gwId"]
productKey = result["productKey"] if result["productKey"] else '?'
Expand Down Expand Up @@ -985,7 +987,9 @@ def _print_device_info( result, note, term, extra_message=None ):


# Scan function
def devices(verbose=False, scantime=None, color=True, poll=True, forcescan=False, byID=False, show_timer=None, discover=True, wantips=None, wantids=None, snapshot=None, assume_yes=False, tuyadevices=[], maxdevices=0): # pylint: disable=W0621, W0102
def devices(verbose=False, scantime=None, color=True, poll=True, forcescan=False, byID=False, show_timer=None,
discover=True, wantips=None, wantids=None, snapshot=None, assume_yes=False, tuyadevices=[],
maxdevices=0): # pylint: disable=W0621, W0102
"""Scans your network for Tuya devices and returns dictionary of devices discovered
devices = tinytuya.deviceScan(verbose)

Expand Down