def GetNetworkName():
  """Return network name (SSID for WLANs) a device is connected to.

  Returns:
    name of the matching network name if possible, None otherwise.
  """
  this_platform = _GetPlatform()
  if this_platform == LINUX:
    cmdline = '/usr/bin/nmcli -t -f NAME,DEVICES conn status'
    # Ignore "Auto " prefix on automatically connecting networks.
    ssid_re = re.compile(r'^(Auto )?([^:]*):.*$')
    try:
      return_code, out, _ = flight_common.Exec(cmdline)
    except OSError:
      logging.exception('Error executing nmcli')
      return

    if out and not return_code:
      for l in out.splitlines():
        res = ssid_re.match(l)
        if res:
          return res.groups()[1]

  elif this_platform == DARWIN:
    cmdline = (
        '/System/Library/PrivateFrameworks/Apple80211.framework/Versions/'
        'Current/Resources/airport -I | '
        'awk \'/ SSID/ {print substr($0, index($0, $2))}\'')
    try:
      return_code, out, _ = flight_common.Exec(cmdline)
    except __HOLE__:
      logging.exception('Error executing airport')
      return
    if out and not return_code:
      return out.strip() or None
dataset/ETHPy150Open google/simian/src/simian/mac/client/network_detect.py/GetNetworkName