PyObjC CoreWLAN Framework Bindings for macOS

12.1 · active · verified Tue Apr 14

The `pyobjc-framework-corewlan` package provides Python bindings for Apple's CoreWLAN framework on macOS. It allows Python applications to interact with Wi-Fi interfaces, retrieve network information, and manage wireless connections. It is part of the larger PyObjC project, which bridges Python and Objective-C, enabling Python developers to leverage macOS Cocoa frameworks directly. The current version is 12.1, with a regular release cadence aligned with macOS SDK updates and Python version support.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to import the CoreWLAN framework and retrieve basic information about the Wi-Fi interface and available networks. Note that modifying Wi-Fi settings (e.g., turning power on/off) typically requires a properly signed application or administrative privileges on macOS, and is not included in this basic example.

import CoreWLAN

def get_wifi_info():
    try:
        # Get the default wireless interface
        interface = CoreWLAN.CWInterface.interface()

        if interface:
            print(f"Current Wi-Fi interface Hardware Address: {interface.hardwareAddress()}")
            print(f"Current Wi-Fi Power Status: {'On' if interface.powerOn() else 'Off'}")

            current_ssid = interface.ssid()
            if current_ssid:
                print(f"Currently connected to network: {current_ssid}")
            else:
                print("Not currently connected to a Wi-Fi network.")

            # List available Wi-Fi networks
            print("\nAvailable Wi-Fi Networks:")
            for network in CoreWLAN.CWInterface.interface().cachedScanResults():
                print(f"  - SSID: {network.ssid()}, RSSI: {network.rssiValue()} dBm")

        else:
            print("No Wi-Fi interface found.")

    except Exception as e:
        print(f"An error occurred: {e}")
        print("Note: Accessing CoreWLAN functionality, especially for modifications, often requires a properly signed application or elevated privileges on macOS.")

if __name__ == "__main__":
    get_wifi_info()

view raw JSON →