Skip to main content

Original Credits

This package is not my own. Full credit for the original code goes to Alastair Houghton [alastair AT alastairs-place DOT net] for his netifaces package. Credit also goes to Kevin Kelley [kelleyk AT kelleyk D0T net] for porting the original netifaces code to Python 3.x and creating the netifaces-py3 package.

What’s Different

This package is a fork from https://github.com/kelleyk/py3k-netifaces with minor changes. These changes include:

  • A version number that follows the standard major.minor.micro naming spec.

  • Update to setup.py which fixes some issues with Python 2.5 (the original package support Python 2.5

  • Removal of minisix as a dependency

  • merged code from https://gist.github.com/opalmer/6558607 which fixes a bug during compilation on Windows. This patch was submitted to the original author of netifaces but was never responded to.

Why This Package Was Created

Normally when problems are encountered in open source Python packages you should submit a patch to the author, have it reviewed, and then finally merged. Sometimes this doesn’t happen however and for one reason or another the package is replicated, fixed, and then released under another name.

So why was netifaces-merged created? There are a few reasons why I’ve created this package but overall the reasons are cross-platform stability and so that a single package can be used across Python versions without the need for external dependencies.

The first problem when trying to accomplish this was that netifaces contained a bug which broke the Windows build. I emailed the author about it and included a patch but unfortunately never received a reply back. Although there were ways to work around it, such as monkey patching the source when running one of my setup.py files, I didn’t think this was a great solution either for my own libraries or for anyone else using netifaces in the future.

Fast forward a few more months and I started working on converting some of my libraries to Python 3.x. netifaces still had not been updated unfortunately but someone, thank you Kevin Kelley, was nice enough to port it to Python 3. The problem this time was the setup.py wasn’t designed to operate in older versions of Python and also relied on a module that as of this writing didn’t exist in PyPi and was not package with netifaces-py3. In addition to this the existing package in PyPi, which is classed as a dumb binary, failed to install into a virtual environment using pip.

I welcome the opportunity to merge both my work and Kevin’s into netifaces but until that happens I’ll be maintaining this package for the foreseeable future.

netifaces 0.9.0

1. What is this?

It’s been annoying me for some time that there’s no easy way to get the address(es) of the machine’s network interfaces from Python. There is a good reason for this difficulty, which is that it is virtually impossible to do so in a portable manner. However, it seems to me that there should be a package you can easy_install that will take care of working out the details of doing so on the machine you’re using, then you can get on with writing Python code without concerning yourself with the nitty gritty of system-dependent low-level networking APIs.

This package attempts to solve that problem.

2. How do I use it?

First you need to install it, which you can do by typing

tar xvzf netifaces-0.4.tar.gz cd netifaces-0.4 python setup.py install

Once that’s done, you’ll need to start Python and do something like the following:

>>> import netifaces

Then if you enter

>>> netifaces.interfaces()
['lo0', 'gif0', 'stf0', 'en0', 'en1', 'fw0']

you’ll see the list of interface identifiers for your machine.

You can ask for the addresses of a particular interface by doing

>>> netifaces.ifaddresses('lo0')
{18: [{'addr': ''}], 2: [{'peer': '127.0.0.1', 'netmask': '255.0.0.0', 'addr': '127.0.0.1'}], 30: [{'peer': '::1', 'netmask': 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff', 'addr': '::1'}, {'peer': '', 'netmask': 'ffff:ffff:ffff:ffff::', 'addr': 'fe80::1%lo0'}]}

Hmmmm. That result looks a bit cryptic; let’s break it apart and explain what each piece means. It returned a dictionary, so let’s look there first:

{ 18: […], 2: […], 30: […] }

Each of the numbers refers to a particular address family. In this case, we have three address families listed; on my system, 18 is AF_LINK (which means the link layer interface, e.g. Ethernet), 2 is AF_INET (normal Internet addresses), and 30 is AF_INET6 (IPv6).

But wait! Don’t use these numbers in your code. The numeric values here are system dependent; fortunately, I thought of that when writing netifaces, so the module declares a range of values that you might need. e.g.

>>> netifaces.AF_LINK
18

Again, on your system, the number may be different.

So, what we’ve established is that the dictionary that’s returned has one entry for each address family for which this interface has an address. Let’s take a look at the AF_INET addresses now:

>>> addrs = netifaces.ifaddresses('lo0')
>>> addrs[netifaces.AF_INET]
[{'peer': '127.0.0.1', 'netmask': '255.0.0.0', 'addr': '127.0.0.1'}]

You might be wondering why this value is a list. The reason is that it’s possible for an interface to have more than one address, even within the same family. I’ll say that again: you can have more than one address of the same type associated with each interface.

Asking for “the” address of a particular interface doesn’t make sense.

Right, so, we can see that this particular interface only has one address, and, because it’s a loopback interface, it’s point-to-point and therefore has a peer address rather than a broadcast address.

Let’s look at a more interesting interface.

>>> addrs = netifaces.ifaddresses('en0')
>>> addrs[netifaces.AF_INET]
[{'broadcast': '10.15.255.255', 'netmask': '255.240.0.0', 'addr': '10.0.1.4'}, {'broadcast': '192.168.0.255', 'addr': '192.168.0.47'}]

This interface has two addresses (see, I told you…) Both of them are regular IPv4 addresses, although in one case the netmask has been changed from its default. The netmask may not appear on your system if it’s set to the default for the address range.

Because this interface isn’t point-to-point, it also has broadcast addresses.

Now, say we want, instead of the IP addresses, to get the MAC address; that is, the hardware address of the Ethernet adapter running this interface. We can do

>>> addrs[netifaces.AF_LINK]
[{'addr': '00:12:34:56:78:9a'}]

Note that this may not be available on platforms without getifaddrs(), unless they happen to implement SIOCGIFHWADDR. Note also that you just get the address; it’s unlikely that you’ll see anything else with an AF_LINK address. Oh, and don’t assume that all AF_LINK addresses are Ethernet; you might, for instance, be on a Mac, in which case:

>>> addrs = netifaces.ifaddresses('fw0')
>>> addrs[netifaces.AF_LINK]
[{'addr': '00:12:34:56:78:9a:bc:de'}]

No, that isn’t an exceptionally long Ethernet MAC address—it’s a FireWire address.

3. This is great! What platforms does it work on?

Well, see, here’s the thing. It’s been tested on Mac OS X, and it seems to work. (OS X helpfully has some of the SIOCGIFxxx ioctl()s, which means that most of those have been tested too, the only glaring exception being the SIOCGIFHWADDR ioctl(), which OS X just doesn’t have.)

It should probably work on most of the other UNIX-like systems with relatively minor changes. If you do have to change something, send it to me at <alastair AT alastairs-place.net> and I’ll see if I can merge it in.

It also works just fine on Windows, using the GetAdaptersInfo() function. Note, though, that on Windows it isn’t possible (yet) to retrieve IPv6 addresses. I don’t use Windows at the moment, so this isn’t a priority for me. If you know how to fix it, drop me a line and I’ll consider adding any necessary code.

4. What license is this under?

It’s an MIT-style license. Here goes:

Copyright (c) 2007, 2008 Alastair Houghton
Copyright (c) 2011 Kevin Kelley
Copyright (c) 2013 Oliver Palmer

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Metadata

Release files for netifaces-merged 0.9.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for netifaces-merged 0.9.0
File Size Uploaded
netifaces-merged-0.9.0.tar.gz 21.8 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for netifaces-merged 0.9.0
File
netifaces_merged-0.9.0-py3.3-win32.egg Legacy Egg format - - Details
netifaces_merged-0.9.0-py3.3-macosx-10.9-x86_64.egg Legacy Egg format - - Details
netifaces_merged-0.9.0-py3.3-linux-x86_64.egg Legacy Egg format - - Details
netifaces_merged-0.9.0-py2.7-win32.egg Legacy Egg format - - Details
netifaces_merged-0.9.0-py2.7-macosx-10.9-intel.egg Legacy Egg format - - Details
netifaces_merged-0.9.0-py2.7-linux-x86_64.egg Legacy Egg format - - Details
netifaces_merged-0.9.0-py2.6-win32.egg Legacy Egg format - - Details
netifaces_merged-0.9.0-py2.6-macosx-10.9-intel.egg Legacy Egg format - - Details
netifaces_merged-0.9.0-py2.6-linux-x86_64.egg Legacy Egg format - - Details
netifaces-merged-0.9.0.win32-py3.3.exe Details
netifaces-merged-0.9.0.win32-py2.7.exe Details
netifaces-merged-0.9.0.win32-py2.6.exe Details

Total release size: 810.0 kB

Release files / netifaces-merged-0.9.0.tar.gz

Download URL netifaces-merged-0.9.0.tar.gz
Size 21.8 kB
Tags Source
SHA-256 checksum
How to use checksums
a3b9e175f0b101be1ccd0146476ae61b09b89b5edd75d31bbaf96c75a7d0dc99
BLAKE2b-256 checksum
How to use checksums
5d65afaea4b9a48cdfa1f512c82be3871582faeb709a9055bbabfa8049a38459
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / netifaces_merged-0.9.0-py3.3-win32.egg

Download URL netifaces_merged-0.9.0-py3.3-win32.egg
Size 12.9 kB
Tags Egg
SHA-256 checksum
How to use checksums
4271d3536e0605e6e2b543dbed91afe90f8d56efe7eeca75eefcecaf5987bcd4
BLAKE2b-256 checksum
How to use checksums
7aa7ea0a131e1bd52d4aabc8f4096063cb729b337d792b70ab42355c7ac38d9d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / netifaces_merged-0.9.0-py3.3-macosx-10.9-x86_64.egg

Download URL netifaces_merged-0.9.0-py3.3-macosx-10.9-x86_64.egg
Size 10.3 kB
Tags Egg
SHA-256 checksum
How to use checksums
ac02c24551669727f01c8f8e8af69527c9cc8362d75e4b66a72f9d6f34ee14d1
BLAKE2b-256 checksum
How to use checksums
fa282502a503522d61ed898633210a1b5f48eb954b3f7beff7b4b45564077c9c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / netifaces_merged-0.9.0-py3.3-linux-x86_64.egg

Download URL netifaces_merged-0.9.0-py3.3-linux-x86_64.egg
Size 21.6 kB
Tags Egg
SHA-256 checksum
How to use checksums
4bcd697b6126685b61a5c716b8afef86a03f1fb17d510541a507c64c079d1653
BLAKE2b-256 checksum
How to use checksums
59d54ab988067b23f048903181111fe57eb7ab0cf411815f7273e756e4b31931
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / netifaces_merged-0.9.0-py2.7-win32.egg

Download URL netifaces_merged-0.9.0-py2.7-win32.egg
Size 12.2 kB
Tags Egg
SHA-256 checksum
How to use checksums
360a229c50282c2cf259b232dd6be0d4d3c85463485c5b0de5d4a156358c0f04
BLAKE2b-256 checksum
How to use checksums
ef8eb9ffd9a89ffafe121f05cfa291f64ef1645655ea055bb77032e3df9634c6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / netifaces_merged-0.9.0-py2.7-macosx-10.9-intel.egg

Download URL netifaces_merged-0.9.0-py2.7-macosx-10.9-intel.egg
Size 13.0 kB
Tags Egg
SHA-256 checksum
How to use checksums
2e2902f8b81fb62826a044cd9d0e8b4a02bc8ed088d2c74727fc9f58f7fdf3a7
BLAKE2b-256 checksum
How to use checksums
0c6049cf3690fafcf9b504b47700670b770626d32f17b2feba43f5138a4bffc5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / netifaces_merged-0.9.0-py2.7-linux-x86_64.egg

Download URL netifaces_merged-0.9.0-py2.7-linux-x86_64.egg
Size 21.2 kB
Tags Egg
SHA-256 checksum
How to use checksums
4007eea8ba446403a545d4a9bd14a3b3c4926aefadf01797335ee6706e511b51
BLAKE2b-256 checksum
How to use checksums
b195956cf85e1e2fee792b0f0c3d4b28ca406693372d124263a073c22a21cb37
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / netifaces_merged-0.9.0-py2.6-win32.egg

Download URL netifaces_merged-0.9.0-py2.6-win32.egg
Size 12.5 kB
Tags Egg
SHA-256 checksum
How to use checksums
91a0aa0f5115d0e02769020805a4eb7a55652aa9acf7f2f167a7a11edf39225b
BLAKE2b-256 checksum
How to use checksums
afd0293126e85a16aee865e11510cd155aaabae6397244d209cdd1a610707da8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / netifaces_merged-0.9.0-py2.6-macosx-10.9-intel.egg

Download URL netifaces_merged-0.9.0-py2.6-macosx-10.9-intel.egg
Size 13.0 kB
Tags Egg
SHA-256 checksum
How to use checksums
08cf2583c10a23595458ef672404377ee65a5b71c7b04fa0c2cc7990032e3428
BLAKE2b-256 checksum
How to use checksums
b57fba62490881f1094406f98c76c73211f20748dcd332b66698d9a994b98915
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / netifaces_merged-0.9.0-py2.6-linux-x86_64.egg

Download URL netifaces_merged-0.9.0-py2.6-linux-x86_64.egg
Size 21.1 kB
Tags Egg
SHA-256 checksum
How to use checksums
4ff742f700b61b9b02aada7eeec401cff56c337fc9fcc2d13209803dd962a974
BLAKE2b-256 checksum
How to use checksums
72c6e28bea02f78288503e2f67bb4f860904825274e972cf6808c83517031b60
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / netifaces-merged-0.9.0.win32-py3.3.exe

Download URL netifaces-merged-0.9.0.win32-py3.3.exe
Size 213.8 kB
Tags Source
SHA-256 checksum
How to use checksums
91712400ef7458f14f826b55715ceb49e76ccdf1953b07a19784dc52d0ac8e2d
BLAKE2b-256 checksum
How to use checksums
2f489350e7faa71406919be5c026e5904b18f985cf94bcf20ea129827e020426
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / netifaces-merged-0.9.0.win32-py2.7.exe

Download URL netifaces-merged-0.9.0.win32-py2.7.exe
Size 218.3 kB
Tags Source
SHA-256 checksum
How to use checksums
fa2f0d5dbc07c59b28e6d02b4c38459db34baeda3f2654d45f1a75a8d69defee
BLAKE2b-256 checksum
How to use checksums
af05adf73933037ffa520948ff1041b36520eac3e7aab06a2f216e3cbc4e5f1f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / netifaces-merged-0.9.0.win32-py2.6.exe

Download URL netifaces-merged-0.9.0.win32-py2.6.exe
Size 218.5 kB
Tags Source
SHA-256 checksum
How to use checksums
72e1154fbdfcdbb67dedcae9ff3b8e6913702a24584f3d95d33533053359a4cf
BLAKE2b-256 checksum
How to use checksums
fcba646cf7fbc59e313e10d0b5687b86d3d9dd47896c6bf685a349b285c8ade4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.9.0 This release

13 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page