1- #!/usr/bin/env python
1+ #!/usr/bin/env python3
22
33##########################################
44# UBNT command line discovery tool #
@@ -95,7 +95,7 @@ def ubntDiscovery(iface):
9595 ubnt_discovery_packet = Ether (dst = "ff:ff:ff:ff:ff:ff" , src = src_mac )/ \
9696 IP (dst = "255.255.255.255" )/ \
9797 UDP (sport = randint (1024 ,65535 ),dport = 10001 )/ \
98- Raw (UBNT_REQUEST_PAYLOAD .decode ('hex ' ))
98+ Raw (bytes . fromhex ( UBNT_REQUEST_PAYLOAD ) .decode ('utf-8 ' ))
9999 ans , unans = srp (ubnt_discovery_packet ,
100100 multi = True , # We want to allow multiple radios to reply to our discovery packet
101101 verbose = 0 , # Suppress scapy output
@@ -110,7 +110,7 @@ def ubntDiscovery(iface):
110110 payload = rcv [IP ].load
111111
112112 # Check for a valid UBNT discovery reply (first 3 bytes of the payload should be \x01\x00\x00)
113- if payload [0 :3 ]. encode ( 'hex' ) == UBNT_REPLY_SIGNATURE :
113+ if bytes . hex ( payload [0 :3 ]) == UBNT_REPLY_SIGNATURE :
114114 Radio = {} # This should be a valid discovery reply packet sent by an Ubiquiti radio
115115 else :
116116 continue # Not a valid UBNT discovery reply, skip to next received packet
@@ -128,21 +128,20 @@ def ubntDiscovery(iface):
128128
129129 # Retrieve payload size (excluding initial signature)
130130 pointer = offset_PayloadRemainingBytes
131- remaining_bytes = int ( payload [pointer ]. encode ( 'hex' ), 16 )
131+ remaining_bytes = payload [pointer ] # decoded as 8-bit unsigned int by default
132132
133133 # Walk the reply payload, staring from offset 04 (just after reply signature and payload size).
134134 pointer += 1
135135 remaining_bytes -= 1
136136 while remaining_bytes > 0 :
137- fieldType = payload [pointer ]. encode ( 'hex' )
137+ fieldType = bytes . hex ( payload [pointer : pointer + 1 ] )
138138 pointer += 1
139139 remaining_bytes -= 1
140- fieldLen = payload [pointer :pointer + 2 ].encode ('hex' ) # Data length is stored as a 16-bit word
141- fieldLen = int ( fieldLen , 16 )
140+ fieldLen = int .from_bytes (payload [pointer :pointer + 2 ], 'big' ) # Data length is stored as a 16-bit word
142141 pointer += 2
143142 remaining_bytes -= 2
144143 fieldData = payload [pointer :pointer + fieldLen ]
145- if fieldType == UBNT_RADIONAME :
144+ if fieldType == UBNT_RADIONAME :
146145 RadioName = fieldData
147146 elif fieldType == UBNT_MODEL_FULL :
148147 RadioModel = fieldData
@@ -151,11 +150,11 @@ def ubntDiscovery(iface):
151150 elif fieldType == UBNT_FIRMWARE :
152151 RadioFirmware = fieldData
153152 elif fieldType == UBNT_UPTIME :
154- RadioUptime = int ( fieldData . encode ( 'hex' ), 16 )
153+ RadioUptime = int . from_bytes ( fieldData , 'big' )
155154 elif fieldType == UBNT_ESSID :
156155 RadioEssid = fieldData
157156 elif fieldType == UBNT_WLAN_MODE :
158- RadioWlanMode = UBNT_WIRELESS_MODES [fieldData ]
157+ RadioWlanMode = UBNT_WIRELESS_MODES [fieldData . decode () ]
159158 elif fieldType == UBNT_MAC_AND_IP :
160159 # There might be several IPs
161160 # Let's use the latest seen that is *not* 169.254.X.X (APIPA)
@@ -169,12 +168,12 @@ def ubntDiscovery(iface):
169168 # Store the data we gathered from the reply packet
170169 Radio ['ip' ] = RadioIP
171170 Radio ['mac' ] = RadioMAC
172- Radio ['name' ] = RadioName
173- Radio ['model' ] = RadioModel
174- Radio ['essid' ] = RadioEssid
175- Radio ['firmware' ] = RadioFirmware
171+ Radio ['name' ] = RadioName . decode ()
172+ Radio ['model' ] = RadioModel . decode ()
173+ Radio ['essid' ] = RadioEssid . decode ()
174+ Radio ['firmware' ] = RadioFirmware . decode ()
176175 Radio ['uptime' ] = RadioUptime
177- Radio ['model_short' ] = RadioModelShort
176+ Radio ['model_short' ] = RadioModelShort . decode ()
178177 Radio ['wlan_mode' ] = RadioWlanMode
179178 RadioList .append (Radio )
180179
0 commit comments