(include_nearby_networks=False)
return airport_info
Returns information about current AirPort connection.

  Args:
    include_nearby_networks: bool, if True a nearby_networks key will be in
      the returned dict with a list of detected SSIDs nearby.

  Returns:
    dict: key value pairs from CWInterface data. If an error occurs or there is
      no Wi-Fi interface: the dict will be empty.
Returns information about current AirPort connection.
Returns information about current AirPort connection .
def GetAirportInfo(include_nearby_networks=False):
  """Returns information about current AirPort connection.

  Args:
    include_nearby_networks: bool, if True a nearby_networks key will be in
      the returned dict with a list of detected SSIDs nearby.

  Returns:
    dict: key value pairs from CWInterface data. If an error occurs or there is
      no Wi-Fi interface: the dict will be empty.
  """
  airport_info = {}
  try:
    objc.loadBundle('CoreWLAN', globals(),
                    bundle_path='/System/Library/Frameworks/CoreWLAN.framework')
  except ImportError:
    logging.error('Could not load CoreWLAN framework.')
    return airport_info

  cw_interface_state = {0: u'Inactive',
                        1: u'Scanning',
                        2: u'Authenticating',
                        3: u'Associating',
                        4: u'Running'}

  cw_security = {-1: u'Unknown',
                 0: u'None',
                 1: u'WEP',
                 2: u'WPA Personal',
                 3: u'WPA Personal Mixed',
                 4: u'WPA2 Personal',
                 6: u'Dynamic WEP',
                 7: u'WPA Enterprise',
                 8: u'WPA Enterprise Mixed',
                 9: u'WPA2 Enterprise',
                 10: u'Enterprise',
                 11: u'WPA3 Personal',
                 12: u'WPA3 Enterprise',
                 13: u'WPA3 Transition'}

  cw_phy_mode = {0: u'None',
                 1: u'802.11a',
                 2: u'802.11b',
                 3: u'802.11g',
                 4: u'802.11n'}

  cw_channel_band = {0: u'Unknown',
                     1: u'2 GHz',
                     2: u'5 GHz'}

  iface = CWInterface.interface()  # pylint: disable=undefined-variable
  if not iface:
    return airport_info

  airport_info['name'] = iface.interfaceName()
  airport_info['hw_address'] = iface.hardwareAddress()
  airport_info['service_active'] = bool(iface.serviceActive())
  airport_info['country_code'] = iface.countryCode()
  airport_info['power'] = bool(iface.powerOn())
  airport_info['SSID'] = iface.ssid()
  airport_info['BSSID'] = iface.bssid()
  airport_info['noise_measurement'] = iface.noiseMeasurement()
  airport_info['phy_mode'] = iface.activePHYMode()
  airport_info['phy_mode_name'] = cw_phy_mode[iface.activePHYMode()]
  airport_info['rssi'] = iface.rssiValue()
  airport_info['state'] = iface.interfaceState()
  airport_info['state_name'] = cw_interface_state[iface.interfaceState()]
  airport_info['transmit_power'] = iface.transmitPower()
  airport_info['transmit_rate'] = iface.transmitRate()

  # Get channel information
  cw_channel = iface.wlanChannel()
  if cw_channel:
    airport_info['channel_number'] = cw_channel.channelNumber()
    airport_info['channel_band'] = cw_channel_band[cw_channel.channelBand()]

  # Get security information
  # If the security setting is unknown iface.security() returns NSIntegerMax
  # which is a very large number and annoying to test for in calling scripts.
  # Change any value larger than 100 (the enum currently ends at 10) to -1.
  security = iface.security()
  if security > 100:
    security = -1
  airport_info['security'] = security
  airport_info['security_name'] = cw_security[security]

  # Get nearby network information, if requested
  if include_nearby_networks:
    nearby_networks = []
    try:
      for nw in iface.scanForNetworksWithName_error_(None, None):
        ssid = nw.ssid()
        if ssid not in nearby_networks:
          nearby_networks.append(ssid)
    except TypeError:
      pass
    airport_info['nearby_networks'] = nearby_networks

  return airport_info
def GetAirportInfo ( include_nearby_networks = False ) : airport_info = { } try : objc . loadBundle ( 'CoreWLAN' , globals ( ) , bundle_path = '/System/Library/Frameworks/CoreWLAN.framework' ) except ImportError : logging . error ( 'Could not load CoreWLAN framework.' ) return airport_info cw_interface_state = { 0 : u'Inactive' , 1 : u'Scanning' , 2 : u'Authenticating' , 3 : u'Associating' , 4 : u'Running' } cw_security = { - 1 : u'Unknown' , 0 : u'None' , 1 : u'WEP' , 2 : u'WPA Personal' , 3 : u'WPA Personal Mixed' , 4 : u'WPA2 Personal' , 6 : u'Dynamic WEP' , 7 : u'WPA Enterprise' , 8 : u'WPA Enterprise Mixed' , 9 : u'WPA2 Enterprise' , 10 : u'Enterprise' , 11 : u'WPA3 Personal' , 12 : u'WPA3 Enterprise' , 13 : u'WPA3 Transition' } cw_phy_mode = { 0 : u'None' , 1 : u'802.11a' , 2 : u'802.11b' , 3 : u'802.11g' , 4 : u'802.11n' } cw_channel_band = { 0 : u'Unknown' , 1 : u'2 GHz' , 2 : u'5 GHz' } iface = CWInterface . interface ( ) # pylint: disable=undefined-variable if not iface : return airport_info airport_info [ 'name' ] = iface . interfaceName ( ) airport_info [ 'hw_address' ] = iface . hardwareAddress ( ) airport_info [ 'service_active' ] = bool ( iface . serviceActive ( ) ) airport_info [ 'country_code' ] = iface . countryCode ( ) airport_info [ 'power' ] = bool ( iface . powerOn ( ) ) airport_info [ 'SSID' ] = iface . ssid ( ) airport_info [ 'BSSID' ] = iface . bssid ( ) airport_info [ 'noise_measurement' ] = iface . noiseMeasurement ( ) airport_info [ 'phy_mode' ] = iface . activePHYMode ( ) airport_info [ 'phy_mode_name' ] = cw_phy_mode [ iface . activePHYMode ( ) ] airport_info [ 'rssi' ] = iface . rssiValue ( ) airport_info [ 'state' ] = iface . interfaceState ( ) airport_info [ 'state_name' ] = cw_interface_state [ iface . interfaceState ( ) ] airport_info [ 'transmit_power' ] = iface . transmitPower ( ) airport_info [ 'transmit_rate' ] = iface . transmitRate ( ) # Get channel information cw_channel = iface . wlanChannel ( ) if cw_channel : airport_info [ 'channel_number' ] = cw_channel . channelNumber ( ) airport_info [ 'channel_band' ] = cw_channel_band [ cw_channel . channelBand ( ) ] # Get security information # If the security setting is unknown iface.security() returns NSIntegerMax # which is a very large number and annoying to test for in calling scripts. # Change any value larger than 100 (the enum currently ends at 10) to -1. security = iface . security ( ) if security > 100 : security = - 1 airport_info [ 'security' ] = security airport_info [ 'security_name' ] = cw_security [ security ] # Get nearby network information, if requested if include_nearby_networks : nearby_networks = [ ] try : for nw in iface . scanForNetworksWithName_error_ ( None , None ) : ssid = nw . ssid ( ) if ssid not in nearby_networks : nearby_networks . append ( ssid ) except TypeError : pass airport_info [ 'nearby_networks' ] = nearby_networks return airport_info