Coder Social home page Coder Social logo

netifaces-2's Introduction

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 or the ip tool
  • The windows gateways API is non-functional

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.

The level of completness differs a little bit with the original version; some address families might not yet be available and PEER addresses are not reported for now. If you need a feature, open an issue and I will do my best to add it.

Gateways also returned the interfaces indexed by integer values. This is a bit odd (IMO) since the integers values for the interface types are system-dependent. Enum values with a more semantic meaning are now used (they are still tied to linux numbers), but you can use old_api=True in their call to get the al45air-style keys back.

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

Linux cp37-abi3 wheels are built on manylinux2_17 aka manylinux2014 and require pip>=19.3
cp36m-manylinux2_17 wheels are unsupported and are being built only as a fallback for systems with only Python 3.6 available.

5. License

This software is distributed under a MIT license.

netifaces-2's People

Contributors

alfrisch avatar martinhoyer avatar samuelyvon avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.