Package: nmcli
nmclinmcli is a python wrapper library for the network-manager cli client.Quick SampleHere is a simple usecase.importnmclitry:print(nmcli.connection())print(nmcli.device())print(nmcli.device.wifi())print(nmcli.general())nmcli.device.wifi_connect('AP1','passphrase')nmcli.connection.modify('AP1',{'ipv4.addresses':'192.168.1.1/24','ipv4.gateway':'192.168.1.255','ipv4.method':'manual'})nmcli.connection.down('AP1')nmcli.connection.up('AP1')nmcli.connection.delete('AP1')exceptExceptionase:print(e)DependencyNetworkManagersudo apt install network-manager(Debian)User who can execute nmcli with sudo with NOPASSWDIf sudo is not needed (like root user), usedisable_use_sudoat the beginning of the process.Compatibility tableObjectCommandStatusgeneralsupportedgeneralstatussupportedgeneralhostnamesupportedgeneralpermissionsnot supportedgeneralloggingnot supportednetworkingsupportednetworkingonsupportednetworkingoffsupportednetworkingconnectivitysupportedradiosupportedradioallsupportedradiowifisupportedradiowwansupportedconnectionsupportedconnectionshowsupportedconnectionupsupportedconnectiondownsupportedconnectionaddsupportedconnectionmodifysupportedconnectionclonenot supportedconnectioneditnot supportedconnectiondeletesupportedconnectionreloadsupportedconnectionloadnot supportedconnectionimportnot supportedconnectionexportnot supporteddevicesupporteddevicestatussupporteddeviceshowsupporteddevicesetnot supporteddeviceconnectsupporteddevicereapplysupporteddevicemodifynot supporteddevicedisconnectsupporteddevicedeletesupporteddevicemonitornot supporteddevicewifisupporteddevicewifi connectsupporteddevicewifi rescansupporteddevicewifi hotspotsupporteddevicelldpnot supportedagentnot supportedagentsecretnot supportedagentpolkitnot supportedagentallnot supportedmonitornot supportedAPIconnectionnmcli.connectionGet a list of connections.nmcli.connection() -> List[Connection]nmcli.connection.addCreate a new connection using specified properties.nmcli.connection.add(
    conn_type: str,
    options: Optional[ConnectionOptions] = None,
    ifname: str = "*",
    name: str = None,
    autoconnect: bool = None) -> Nonenmcli.connection.modifyAdd, modify or remove properties in the connection profile.nmcli.connection.modify(name: str, options: ConnectionOptions) -> Nonenmcli.connection.deleteDelete a configured connection.Thewaitargument applies the same effect to the command as the--waitoption. If it is omitted, the default behavior is followed.nmcli.connection.delete(name: str, wait: int = None) -> Nonenmcli.connection.upActivate a connection.Thewaitargument applies the same effect to the command as the--waitoption. If it is omitted, the default behavior is followed.nmcli.connection.up(name: str, wait: int = None) -> Nonenmcli.connection.downDeactivate a connection from a device without preventing the device from further auto-activation.Thewaitargument applies the same effect to the command as the--waitoption. If it is omitted, the default behavior is followed.nmcli.connection.down(name: str, wait: int = None) -> Nonenmcli.connection.showShow details for specified connections.nmcli.connection.show(name: str) -> ConnectionDetailsnmcli.connection.reloadReload all connection files from disk.nmcli.connection.reload() -> Nonedevicenmcli.devicePrint status of devices.nmcli.device() -> List[Device]nmcli.device.statusShow status for all devices.nmcli.device.status() -> List[Device]nmcli.device.showShow details of device.Thefieldsargument applies the same effect to the command as the-f | --fieldsoption. If it is omitted, the default behavior is followed.nmcli.device.show(ifname: str, fields: str = None) -> DeviceDetailsnmcli.device.show_allShow details of devices.Thefieldsargument applies the same effect to the command as the-f | --fieldsoption. If it is omitted, the default behavior is followed.nmcli.device.show_all(fields: str = None) -> List[DeviceDetails]nmcli.device.connectConnect the device.Thewaitargument applies the same effect to the command as the--waitoption. If it is omitted, the default behavior is followed.nmcli.device.connect(ifname: str, wait: int = None) -> Nonenmcli.device.disconnectDisconnect devices.Thewaitargument applies the same effect to the command as the--waitoption. If it is omitted, the default behavior is followed.nmcli.device.disconnect(ifname: str, wait: int = None) -> Nonenmcli.device.reapplyAttempts to update device with changes to the currently active connection made since it was last applied.nmcli.device.reapply(ifname: str) -> Nonenmcli.device.deleteDelete the software devices.Thewaitargument applies the same effect to the command as the--waitoption. If it is omitted, the default behavior is followed.nmcli.device.delete(ifname: str, wait: int = None) -> Nonenmcli.device.wifiList available Wi-Fi access points.nmcli.device.wifi(ifname: str = None, rescan: bool = None) -> List[DeviceWifi]nmcli.device.wifi_connectConnect to a Wi-Fi network specified by SSID or BSSID.Thewaitargument applies the same effect to the command as the--waitoption. If it is omitted, the default behavior is followed.nmcli.device.wifi_connect(ssid: str,
                          password: str,
                          ifname: str = None,
                          wait: int = None) -> Nonenmcli.device.wifi_hotspotCreate a Wi-Fi hotspotnmcli.device.wifi_hotspot(ifname: str = None,
                          con_name: str = None,
                          ssid: str = None,
                          band: str = None,
                          channel: int = None,
                          password: str = None) -> Hotspotnmcli.device.wifi_rescanRequest that NetworkManager immediately re-scan for available access points.nmcli.device.wifi_rescan(ifname: str = None, ssid: str = None) -> Nonegeneralnmcli.generalShow overall status of NetworkManager.nmcli.general() -> Generalnmcli.general.statusShow overall status of NetworkManager.nmcli.general.status() -> Generalnmcli.general.get_hostnameGet persistent system hostname.nmcli.general.get_hostname() -> strnmcli.general.set_hostnameChange persistent system hostname.nmcli.general.set_hostname(hostname: str) -> Nonenetworkingnmcli.networkingGet network connectivity state.nmcli.networking() -> NetworkConnectivitynmcli.networking.onSwitch networking on.nmcli.networking.on() -> Nonenmcli.networking.offSwitch networking off.nmcli.networking.off() -> Nonenmcli.networking.connectivityGet network connectivity state.The optional 'check' argument makes NetworkManager re-check the connectivity.nmcli.networking.connectivity(check:bool = False) -> NetworkConnectivityradionmcli.radioGet status of all radio switches.nmcli.radio() -> Radionmcli.radio.allGet status of all radio switches.nmcli.radio.all() -> Radionmcli.radio.all_onTurn on all radio switches.nmcli.radio.all_on() -> Nonenmcli.radio.all_offTurn off all radio switches.nmcli.radio.all_off() -> Nonenmcli.radio.wifiGet status of Wi-Fi radio switch.nmcli.radio.wifi() -> boolnmcli.radio.wifi_onTurn on Wi-Fi radio switches.nmcli.radio.wifi_on() -> Nonenmcli.radio.wifi_offTurn off Wi-Fi radio switches.nmcli.radio.wifi_off() -> Nonenmcli.radio.wwanGet status of mobile broadband radio switch.nmcli.radio.wwan() -> boolnmcli.radio.wwan_onTurn on mobile broadband radio switches.nmcli.radio.wwan_on() -> Nonenmcli.radio.wwan_offTurn off mobile broadband radio switches.nmcli.radio.wwan_off() -> Noneothernmcli.disable_use_sudoDisable the use of sudo.nmcli.disable_use_sudo() -> Nonenmcli.set_langChange the environment variable LANG from the defaultC.
Run this command when you want to useC.UTF-8.nmcli.set_lang(lang: str) -> NoneChange Log1.3.0Added rescan parameter tonmcli.device.wifi.1.2.0Added support for encodings other than UTF-8.1.1.2Fixed a problem with environment variables being scraped.1.1.1Include LICENSE.txt in the tar.1.1.0Added fields option tonmcli.device.showandnmcli.device.show_all1.0.0Handle connection failure exceptions withnmcli.device.wifi_connect.Added wait param tonmcli.connection.delete,nmcli.connection.up,nmcli.connection.down,nmcli.device.connect,nmcli.device.disconnect,nmcli.device.delete,nmcli.device.wifi_connect.0.9.0Added ifname param to wifi.0.8.0Added support for changing the LANG environment variable.0.7.0Added ifname param to wifi_connect.0.6.1Fixed a bug in the autoconnect parameter of the nmcli.connection.add method (made the default value conform to the specification of nmcli connection add).0.6.0Added BSSID and FREQ to DeviceWifi.0.5.0Added support for "nmcli device wifi hotspot".Added support for "nmcli device wifi rescan".0.4.2Fixed the parsing of device wifi.0.4.1Fixed parsing when SSID has a space.0.4.0Added disabling of sudo usage.Added support for parsing the execution results of recent versions of the nmcli device wifi command.0.3.1Fixed device status and device wifi parsing bug.0.3.0Added networking and radio APIs.Added more APIs for connection, device and general.Changed the properties of the General data class.Changed throw a ValueError exception if the regular expression pattern is not matched.0.2.2Fix the parsing bug of connection names that contain spaces (connection.show).Added getting items that begin with a capital letter.0.2.1Fix the parsing bug of connection names that contain spaces.0.2.0Added dummy classes.0.1.0Initial release.LicenseMIT