wpas-dbus-new-getall.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #!/usr/bin/python
  2. import dbus
  3. import sys, os
  4. import time
  5. import gobject
  6. WPAS_DBUS_SERVICE = "fi.w1.wpa_supplicant1"
  7. WPAS_DBUS_INTERFACE = "fi.w1.wpa_supplicant1"
  8. WPAS_DBUS_OPATH = "/fi/w1/wpa_supplicant1"
  9. WPAS_DBUS_INTERFACES_INTERFACE = "fi.w1.wpa_supplicant1.Interface"
  10. WPAS_DBUS_INTERFACES_OPATH = "/fi/w1/wpa_supplicant1/Interfaces"
  11. WPAS_DBUS_BSS_INTERFACE = "fi.w1.wpa_supplicant1.Interface.BSS"
  12. def showBss(bss):
  13. net_obj = bus.get_object(WPAS_DBUS_SERVICE, bss)
  14. net = dbus.Interface(net_obj, WPAS_DBUS_BSS_INTERFACE)
  15. props = net_obj.GetAll(WPAS_DBUS_BSS_INTERFACE,
  16. dbus_interface=dbus.PROPERTIES_IFACE)
  17. print props
  18. props = net_obj.Get(WPAS_DBUS_BSS_INTERFACE, 'Properties',
  19. dbus_interface=dbus.PROPERTIES_IFACE)
  20. #print props
  21. # Convert the byte-array for SSID and BSSID to printable strings
  22. bssid = ""
  23. for item in props['BSSID']:
  24. bssid = bssid + ":%02x" % item
  25. bssid = bssid[1:]
  26. ssid = byte_array_to_string(props["SSID"])
  27. wpa = "no"
  28. if props.has_key("WPAIE"):
  29. wpa = "yes"
  30. wpa2 = "no"
  31. if props.has_key("RSNIE"):
  32. wpa2 = "yes"
  33. freq = 0
  34. if props.has_key("Frequency"):
  35. freq = props["Frequency"]
  36. caps = props["Capabilities"]
  37. qual = props["Quality"]
  38. level = props["Level"]
  39. noise = props["Noise"]
  40. maxrate = props["MaxRate"] / 1000000
  41. print " %s :: ssid='%s' wpa=%s wpa2=%s quality=%d%% rate=%d freq=%d" % (bssid, ssid, wpa, wpa2, qual, maxrate, freq)
  42. def scanDone(success):
  43. gobject.MainLoop().quit()
  44. print "Scan done: success=%s" % success
  45. res = if_obj.Get(WPAS_DBUS_INTERFACES_INTERFACE, 'BSSs',
  46. dbus_interface=dbus.PROPERTIES_IFACE)
  47. props = if_obj.GetAll(WPAS_DBUS_INTERFACES_INTERFACE,
  48. dbus_interface=dbus.PROPERTIES_IFACE)
  49. print props
  50. print "Scanned wireless networks:"
  51. for opath in res:
  52. print opath
  53. showBss(opath)
  54. def main():
  55. bus = dbus.SystemBus()
  56. wpas_obj = bus.get_object("fi.w1.wpa_supplicant1",
  57. "/fi/w1/wpa_supplicant1")
  58. props = wpas_obj.GetAll("fi.w1.wpa_supplicant1",
  59. dbus_interface=dbus.PROPERTIES_IFACE)
  60. print "GetAll(fi.w1.wpa_supplicant1, /fi/w1/wpa_supplicant1):"
  61. print props
  62. if len(sys.argv) != 2:
  63. os._exit(1)
  64. ifname = sys.argv[1]
  65. wpas = dbus.Interface(wpas_obj, "fi.w1.wpa_supplicant1")
  66. path = wpas.GetInterface(ifname)
  67. if_obj = bus.get_object("fi.w1.wpa_supplicant1", path)
  68. props = if_obj.GetAll("fi.w1.wpa_supplicant1.Interface",
  69. dbus_interface=dbus.PROPERTIES_IFACE)
  70. print
  71. print "GetAll(fi.w1.wpa_supplicant1.Interface, %s):" % (path)
  72. print props
  73. props = if_obj.GetAll("fi.w1.wpa_supplicant1.Interface.WPS",
  74. dbus_interface=dbus.PROPERTIES_IFACE)
  75. print
  76. print "GetAll(fi.w1.wpa_supplicant1.Interface.WPS, %s):" % (path)
  77. print props
  78. res = if_obj.Get("fi.w1.wpa_supplicant1.Interface", 'BSSs',
  79. dbus_interface=dbus.PROPERTIES_IFACE)
  80. if len(res) > 0:
  81. bss_obj = bus.get_object("fi.w1.wpa_supplicant1", res[0])
  82. props = bss_obj.GetAll("fi.w1.wpa_supplicant1.Interface.BSS",
  83. dbus_interface=dbus.PROPERTIES_IFACE)
  84. print
  85. print "GetAll(fi.w1.wpa_supplicant1.Interface.BSS, %s):" % (res[0])
  86. print props
  87. res = if_obj.Get("fi.w1.wpa_supplicant1.Interface", 'Networks',
  88. dbus_interface=dbus.PROPERTIES_IFACE)
  89. if len(res) > 0:
  90. net_obj = bus.get_object("fi.w1.wpa_supplicant1", res[0])
  91. props = net_obj.GetAll("fi.w1.wpa_supplicant1.Interface.Network",
  92. dbus_interface=dbus.PROPERTIES_IFACE)
  93. print
  94. print "GetAll(fi.w1.wpa_supplicant1.Interface.Network, %s):" % (res[0])
  95. print props
  96. if __name__ == "__main__":
  97. main()