diff --git a/prog/usb-flasher/usb-flash.py b/prog/usb-flasher/usb-flash.py index 6f89b31..b1676ae 100755 --- a/prog/usb-flasher/usb-flash.py +++ b/prog/usb-flasher/usb-flash.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 ''' Copyright (C) 2016 Bastille Networks @@ -25,8 +25,8 @@ # Check pyusb dependency try: from usb import core as _usb_core -except ImportError, ex: - print ''' +except ImportError as ex: + print (''' ------------------------------------------ | PyUSB was not found or is out of date. | ------------------------------------------ @@ -34,7 +34,7 @@ Please update PyUSB using pip: sudo pip install -U -I pip && sudo pip install -U -I pyusb -''' +''') sys.exit(1) # USB timeout sufficiently long for operating in a VM @@ -42,7 +42,7 @@ # Verify that we received a command line argument if len(sys.argv) < 2: - print 'Usage: ./usb-flash.py path-to-firmware.bin' + print ('Usage: ./usb-flash.py path-to-firmware.bin') quit() # Read in the firmware @@ -50,7 +50,7 @@ data = f.read() # Zero pad the data to a multiple of 512 bytes -data += '\000' * (512 - len(data) % 512) +data += b'\000' * (512 - len(data) % 512) # Find an attached device running CrazyRadio or RFStorm firmware logging.info("Looking for a compatible device that can jump to the Nordic bootloader") @@ -93,7 +93,7 @@ # Write the data, one page at a time logging.info("Writing image to flash") -page_count = len(data) / 512 +page_count = int(len(data) / 512) for page in range(page_count): # Tell the bootloader that we are going to write a page diff --git a/tools/lib/common.py b/tools/lib/common.py index 503b5f2..119e5e2 100644 --- a/tools/lib/common.py +++ b/tools/lib/common.py @@ -17,7 +17,7 @@ import logging, argparse -from nrf24 import * +from lib.nrf24 import * channels = [] args = None diff --git a/tools/lib/nrf24.py b/tools/lib/nrf24.py index a0e1a01..342cc94 100644 --- a/tools/lib/nrf24.py +++ b/tools/lib/nrf24.py @@ -21,8 +21,8 @@ # Check pyusb dependency try: from usb import core as _usb_core -except ImportError, ex: - print ''' +except ImportError as ex: + print (''' ------------------------------------------ | PyUSB was not found or is out of date. | ------------------------------------------ @@ -30,7 +30,7 @@ Please update PyUSB using pip: sudo pip install -U -I pip && sudo pip install -U -I pyusb -''' +''') sys.exit(1) # USB commands @@ -65,14 +65,14 @@ def __init__(self, index=0): try: self.dongle = list(usb.core.find(idVendor=0x1915, idProduct=0x0102, find_all=True))[index] self.dongle.set_configuration() - except usb.core.USBError, ex: + except usb.core.USBError as ex: raise ex except: raise Exception('Cannot find USB dongle.') # Put the radio in pseudo-promiscuous mode def enter_promiscuous_mode(self, prefix=[]): - self.send_usb_command(ENTER_PROMISCUOUS_MODE, [len(prefix)]+map(ord, prefix)) + self.send_usb_command(ENTER_PROMISCUOUS_MODE, [len(prefix)]+list(set(map(ord, prefix)))) self.dongle.read(0x81, 64, timeout=nrf24.usb_timeout) if len(prefix) > 0: logging.debug('Entered promiscuous mode with address prefix {0}'. diff --git a/tools/nrf24-continuous-tone-test.py b/tools/nrf24-continuous-tone-test.py index 6023396..7b49450 100755 --- a/tools/nrf24-continuous-tone-test.py +++ b/tools/nrf24-continuous-tone-test.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 ''' Copyright (C) 2016 Bastille Networks diff --git a/tools/nrf24-network-mapper.py b/tools/nrf24-network-mapper.py index 1d36505..3360e28 100755 --- a/tools/nrf24-network-mapper.py +++ b/tools/nrf24-network-mapper.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 ''' Copyright (C) 2016 Bastille Networks @@ -24,7 +24,7 @@ common.init_args('./nrf24-network-mapper.py') common.parser.add_argument('-a', '--address', type=str, help='Known address', required=True) common.parser.add_argument('-k', '--ack_timeout', type=int, help='ACK timeout in microseconds, accepts [250,4000], step 250', default=500) -common.parser.add_argument('-r', '--retries', type=int, help='Auto retry limit, accepts [0,15]', default='5', choices=xrange(0, 16), metavar='RETRIES') +common.parser.add_argument('-r', '--retries', type=int, help='Auto retry limit, accepts [0,15]', default='5', choices=range(0, 16), metavar='RETRIES') common.parser.add_argument('-p', '--ping_payload', type=str, help='Ping payload, ex 0F:0F:0F:0F', default='0F:0F:0F:0F', metavar='PING_PAYLOAD') common.parse_and_init() diff --git a/tools/nrf24-scanner.py b/tools/nrf24-scanner.py index b87da64..11d8f59 100755 --- a/tools/nrf24-scanner.py +++ b/tools/nrf24-scanner.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 ''' Copyright (C) 2016 Bastille Networks @@ -27,7 +27,7 @@ common.parse_and_init() # Parse the prefix addresses -prefix_address = common.args.prefix.replace(':', '').decode('hex') +prefix_address = common.args.prefix.replace(':', '').encode().decode('hex') if len(prefix_address) > 5: raise Exception('Invalid prefix address: {0}'.format(args.address)) diff --git a/tools/nrf24-sniffer.py b/tools/nrf24-sniffer.py index c07eb00..f8fed6b 100755 --- a/tools/nrf24-sniffer.py +++ b/tools/nrf24-sniffer.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 ''' Copyright (C) 2016 Bastille Networks @@ -25,7 +25,7 @@ common.parser.add_argument('-a', '--address', type=str, help='Address to sniff, following as it changes channels', required=True) common.parser.add_argument('-t', '--timeout', type=float, help='Channel timeout, in milliseconds', default=100) common.parser.add_argument('-k', '--ack_timeout', type=int, help='ACK timeout in microseconds, accepts [250,4000], step 250', default=250) -common.parser.add_argument('-r', '--retries', type=int, help='Auto retry limit, accepts [0,15]', default=1, choices=xrange(0, 16), metavar='RETRIES') +common.parser.add_argument('-r', '--retries', type=int, help='Auto retry limit, accepts [0,15]', default=1, choices=range(0, 16), metavar='RETRIES') common.parser.add_argument('-p', '--ping_payload', type=str, help='Ping payload, ex 0F:0F:0F:0F', default='0F:0F:0F:0F', metavar='PING_PAYLOAD') common.parse_and_init()