Skip to main content

Portable network interface information

Project description

netifaces (2)

1. What is this?

The original netifaces was abandonned by it's maintainer, leaving us without the option to get network addresses of any kind in Python. Unfortunately, the original sources are more akin to arcane magic, so picking where it's been left off is a difficult task.

I decided to rewrite netifaces, keeping the almost exact same API and adding the following:

  • Support for future python versions
  • Type annotations
  • Maybe a more "queriable" API in the future

This project aims to be a drop-in replacement for those project who use netifaces, but I do not guarantee anything.

1.1 What is not working right-now

  • The gateways API is only working if your system has a /proc/net/route file
  • The windows API is non-functional

The following section is taken from the origin netifaces:

2. Usage

For now the API is the same as the original netifaces, so please refer to it.

Install:

pip install netifaces2

Import:

>>> import netifaces
>>> netifaces.interfaces()  
    ...
>>> netifaces.ifaddresses('en0')
    ...
>>> netifacs.gateways()
    ...

3. API differences between this and al45tair/netifaces

gateways

The gateways function does not support indexing through the default special key. This is because it makes a sane typing definition difficult to write and be understandable. Instead, if you want the same functionality, the following is exposed:

>>> netifaces.default_gateway()
    ...

The result will be the default gateway for each interface type. The result may be an empty dict if no default route is set.

AF_ Constants

In the previous version of netifaces the AF_ constants' value were assigned to be platform independent. This has the nice effect of abstracting the OS when accessing the information of a network layer. However after consideration, it does not feel like the right place to provide abstraction. If you update your project's dependencies to this version of netifaces, be wary of this change. For instance, on linux you may need to replace AF_LINK with AF_PACKET to get mac addresses.

In the future, an extra API will allow accessing a specific layer's information by querying for it, without using the platform's constant.

4. Platform support

Wheels

Building Linux, Windows and macOS cp37-abi3 wheels (requires Python 3.7 and newer)
Install using pip:
python -m pip install netifaces2

Linux

Targeting manylinux_2_28 (requires pip>=20.3)
Building also cp36m-manylinux2014 wheels for distros using Python 3.6

5. License

This software is distributed under a MIT license.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

netifaces2-0.0.14.tar.gz (10.2 kB view hashes)

Uploaded Source

Built Distributions

netifaces2-0.0.14-cp37-abi3-win_amd64.whl (121.1 kB view hashes)

Uploaded CPython 3.7+ Windows x86-64

netifaces2-0.0.14-cp37-abi3-musllinux_1_1_x86_64.whl (1.2 MB view hashes)

Uploaded CPython 3.7+ musllinux: musl 1.1+ x86-64

netifaces2-0.0.14-cp37-abi3-musllinux_1_1_i686.whl (1.3 MB view hashes)

Uploaded CPython 3.7+ musllinux: musl 1.1+ i686

netifaces2-0.0.14-cp37-abi3-musllinux_1_1_armv7l.whl (1.3 MB view hashes)

Uploaded CPython 3.7+ musllinux: musl 1.1+ ARMv7l

netifaces2-0.0.14-cp37-abi3-musllinux_1_1_aarch64.whl (1.2 MB view hashes)

Uploaded CPython 3.7+ musllinux: musl 1.1+ ARM64

netifaces2-0.0.14-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.1 MB view hashes)

Uploaded CPython 3.7+ manylinux: glibc 2.17+ x86-64

netifaces2-0.0.14-cp37-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.2 MB view hashes)

Uploaded CPython 3.7+ manylinux: glibc 2.17+ s390x

netifaces2-0.0.14-cp37-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.2 MB view hashes)

Uploaded CPython 3.7+ manylinux: glibc 2.17+ ppc64le

netifaces2-0.0.14-cp37-abi3-manylinux_2_17_ppc64.manylinux2014_ppc64.whl (1.2 MB view hashes)

Uploaded CPython 3.7+ manylinux: glibc 2.17+ ppc64

netifaces2-0.0.14-cp37-abi3-manylinux_2_17_i686.manylinux2014_i686.whl (1.1 MB view hashes)

Uploaded CPython 3.7+ manylinux: glibc 2.17+ i686

netifaces2-0.0.14-cp37-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.1 MB view hashes)

Uploaded CPython 3.7+ manylinux: glibc 2.17+ ARMv7l

netifaces2-0.0.14-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.1 MB view hashes)

Uploaded CPython 3.7+ manylinux: glibc 2.17+ ARM64

netifaces2-0.0.14-cp37-abi3-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (495.5 kB view hashes)

Uploaded CPython 3.7+ macOS 10.9+ universal2 (ARM64, x86-64) macOS 10.9+ x86-64 macOS 11.0+ ARM64

netifaces2-0.0.14-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.1 MB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.17+ x86-64

netifaces2-0.0.14-cp36-cp36m-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.2 MB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.17+ s390x

netifaces2-0.0.14-cp36-cp36m-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.2 MB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.17+ ppc64le

netifaces2-0.0.14-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.1 MB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.17+ ARM64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page