airport - macOS


Overview

The airport command on macOS is used to interact with the wireless networking functionalities of your Mac. It allows you to manage Wi-Fi connections and gather network information. This utility is especially useful for network diagnostics, configuration changes, and monitoring the wireless network environment.

Syntax

airport command is not directly accessible from the command line without specifying its full path. The typical syntax to use this command is:

/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport [options]

Alternatively, you can create a symbolic link to make the command more accessible:

sudo ln -s /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport /usr/local/bin/airport

After creating the symbolic link, you can simply use:

airport [options]

Options/Flags

  • -I, --getinfo: Displays information about the current wireless network connection.
  • -s, --scan=[<SSID>]: Scans for available wireless networks. Optionally, you can specify an SSID to look for a particular network.
  • -z, --disassociate: Disconnects from any current wireless network.
  • -i, --ibss=<SSID>: Creates a computer-to-computer network with the specified SSID.
  • -x, --xml: Outputs the scan results in XML format, which can be useful for scripting and automation.
  • -P, --psk=<SSID> <passphrase>: Displays the generated PSK (Pre-Shared Key) for the specified SSID and passphrase.

Examples

Scanning for Wi-Fi networks:

airport -s

Connecting to a network:
First, create a network profile, then:

networksetup -setairportnetwork en0 SSID PASSPHRASE

Getting detailed information about the current connection:

airport -I

Creating an ad-hoc network:

airport -i MyAdHocNetwork

Common Issues

  • Permissions Issues: Users may encounter permission errors when attempting to create symbolic links or execute certain functionalities. Run commands with sudo to resolve permission-related issues.
  • Interface Not Found: Make sure the networking interface (e.g., en0) is correctly specified and active. Use networksetup -listallhardwareports to check available interfaces.

Integration

The airport command can be integrated with shell scripts or combined with other commands like grep for more complex tasks:

Example: Script to monitor signal strength:

#!/bin/bash
while true; do
  /usr/local/bin/airport -I | grep CtlRSSI
  sleep 5
done
  • networksetup: Allows configuration and management of network settings on macOS.
  • ifconfig: A traditional Unix command to configure and manage network interface parameters.

For more detailed information on Apple’s proprietary tools and networking commands, consider visiting the official Apple developer documentation or MacOS support pages.