import network
import binascii
import rp2
rp2.country('us')
wlan = network.WLAN() #  network.WLAN(network.STA_IF)
wlan.active(True)
networks = wlan.scan() # list with tuples (ssid, bssid, channel, RSSI, security, hidden)
networks.sort(key=lambda x:x[3],reverse=True) # sorted on RSSI (3)
#for i, w in enumerate(networks):
#      print(i+1, w[0].decode(), binascii.hexlify(w[1]).decode(), w[2], w[3], w[4], w[5])
#      print('%2d %-30s %16s %4d %4d %4d %4d' %(i+1, w[0].decode(), binascii.hexlify(w[1]).decode(), w[2], w[3], w[4], w[5]))
#      print(type(i+1), type(w[0].decode()), type(binascii.hexlify(w[1]).decode()), type(w[2]), type(w[3]), type(w[4]), type(w[5]))

for i, w in enumerate(networks):
#      print(i+1, w[0].decode(), binascii.hexlify(w[1]).decode(), w[2], w[3], w[4], w[5])
      print('%2d %-30s %16s %4d %4d %4d %4d' %(i+1, w[0].decode(), binascii.hexlify(w[1]).decode(), w[2], w[3], w[4], w[5]))
#      print(type(i+1), type(w[0].decode()), type(binascii.hexlify(w[1]).decode()), type(w[2]), type(w[3]), type(w[4]), type(w[5]))
