Commit 3fa30a70 authored by Thomas Goirand's avatar Thomas Goirand

Updated to upstream 0.10.4

parent a87c2caa
This diff is collapsed.
netifaces 0.4 netifaces 0.10.4
============= ================
.. image:: https://drone.io/bitbucket.org/al45tair/netifaces/status.png
:target: https://drone.io/bitbucket.org/al45tair/netifaces/latest
:alt: Build Status
1. What is this? 1. What is this?
---------------- ----------------
...@@ -18,55 +22,55 @@ This package attempts to solve that problem. ...@@ -18,55 +22,55 @@ This package attempts to solve that problem.
2. How do I use it? 2. How do I use it?
------------------- -------------------
First you need to install it, which you can do by typing First you need to install it, which you can do by typing::
tar xvzf netifaces-0.4.tar.gz tar xvzf netifaces-0.10.4.tar.gz
cd netifaces-0.4 cd netifaces-0.10.4
python setup.py install python setup.py install
Once that's done, you'll need to start Python and do something like the Once that's done, you'll need to start Python and do something like the
following: following::
>>> import netifaces >>> import netifaces
Then if you enter Then if you enter
>>> netifaces.interfaces() >>> netifaces.interfaces()
['lo0', 'gif0', 'stf0', 'en0', 'en1', 'fw0'] ['lo0', 'gif0', 'stf0', 'en0', 'en1', 'fw0']
you'll see the list of interface identifiers for your machine. you'll see the list of interface identifiers for your machine.
You can ask for the addresses of a particular interface by doing You can ask for the addresses of a particular interface by doing
>>> netifaces.ifaddresses('lo0') >>> 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'}]} {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 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: what each piece means. It returned a dictionary, so let's look there first::
{ 18: [...], 2: [...], 30: [...] } { 18: [...], 2: [...], 30: [...] }
Each of the numbers refers to a particular address family. In this case, we 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 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 the link layer interface, e.g. Ethernet), 2 is ``AF_INET`` (normal Internet
addresses), and 30 is AF_INET6 (IPv6). addresses), and 30 is ``AF_INET6`` (IPv6).
But wait! Don't use these numbers in your code. The numeric values here are 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 system dependent; fortunately, I thought of that when writing netifaces, so
the module declares a range of values that you might need. e.g. the module declares a range of values that you might need. e.g.
>>> netifaces.AF_LINK >>> netifaces.AF_LINK
18 18
Again, on your system, the number may be different. Again, on your system, the number may be different.
So, what we've established is that the dictionary that's returned has one 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 entry for each address family for which this interface has an address. Let's
take a look at the AF_INET addresses now: take a look at the ``AF_INET`` addresses now:
>>> addrs = netifaces.ifaddresses('lo0') >>> addrs = netifaces.ifaddresses('lo0')
>>> addrs[netifaces.AF_INET] >>> addrs[netifaces.AF_INET]
[{'peer': '127.0.0.1', 'netmask': '255.0.0.0', 'addr': '127.0.0.1'}] [{'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 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 possible for an interface to have more than one address, even within the
...@@ -81,9 +85,9 @@ has a *peer* address rather than a broadcast address. ...@@ -81,9 +85,9 @@ has a *peer* address rather than a broadcast address.
Let's look at a more interesting interface. Let's look at a more interesting interface.
>>> addrs = netifaces.ifaddresses('en0') >>> addrs = netifaces.ifaddresses('en0')
>>> addrs[netifaces.AF_INET] >>> 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'}] [{'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 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 regular IPv4 addresses, although in one case the netmask has been changed
...@@ -96,46 +100,71 @@ Now, say we want, instead of the IP addresses, to get the MAC address; that ...@@ -96,46 +100,71 @@ 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 is, the hardware address of the Ethernet adapter running this interface. We
can do can do
>>> addrs[netifaces.AF_LINK] >>> addrs[netifaces.AF_LINK]
[{'addr': '00:12:34:56:78:9a'}] [{'addr': '00:12:34:56:78:9a'}]
Note that this may not be available on platforms without getifaddrs(), unless Note that this may not be available on platforms without getifaddrs(), unless
they happen to implement SIOCGIFHWADDR. Note also that you just get the 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. 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 Oh, and don't assume that all ``AF_LINK`` addresses are Ethernet; you might, for
instance, be on a Mac, in which case: instance, be on a Mac, in which case:
>>> addrs = netifaces.ifaddresses('fw0') >>> addrs = netifaces.ifaddresses('fw0')
>>> addrs[netifaces.AF_LINK] >>> addrs[netifaces.AF_LINK]
[{'addr': '00:12:34:56:78:9a:bc:de'}] [{'addr': '00:12:34:56:78:9a:bc:de'}]
No, that isn't an exceptionally long Ethernet MAC address---it's a FireWire No, that isn't an exceptionally long Ethernet MAC address---it's a FireWire
address. address.
3. This is great! What platforms does it work on? As of version 0.10.0, you can also obtain a list of gateways on your
-------------------------------------------------- machine:
>>> netifaces.gateways()
{2: [('10.0.1.1', 'en0', True), ('10.2.1.1', 'en1', False)], 30: [('fe80::1', 'en0', True)], 'default': { 2: ('10.0.1.1', 'en0'), 30: ('fe80::1', 'en0') }}
This dictionary is keyed on address family---in this case, ``AF_INET``---and
each entry is a list of gateways as ``(address, interface, is_default)`` tuples.
Notice that here we have two separate gateways for IPv4 (``AF_INET``); some
operating systems support configurations like this and can either route packets
based on their source, or based on administratively configured routing tables.
For convenience, we also allow you to index the dictionary with the special
value ``'default'``, which returns a dictionary mapping address families to the
default gateway in each case. Thus you can get the default IPv4 gateway with
>>> gws = netifaces.gateways()
>>> gws['default'][netifaces.AF_INET]
('10.0.1.1', 'en0')
Well, see, here's the thing. It's been tested on Mac OS X, and it seems to Do note that there may be no default gateway for any given address family;
work. (OS X helpfully has some of the SIOCGIFxxx ioctl()s, which means that this is currently very common for IPv6 and much less common for IPv4 but it
most of those have been tested too, the only glaring exception being the can happen even for ``AF_INET``.
SIOCGIFHWADDR ioctl(), which OS X just doesn't have.)
It should probably work on most of the other UNIX-like systems with relatively BTW, if you're trying to configure your machine to have multiple gateways for
minor changes. If you do have to change something, send it to me at the same address family, it's a very good idea to check the documentation for
<alastair AT alastairs-place.net> and I'll see if I can merge it in. your operating system *very* carefully, as some systems become extremely
confused or route packets in a non-obvious manner.
It also works just fine on Windows, using the GetAdaptersInfo() function. I'm very interested in hearing from anyone (on any platform) for whom the
Note, though, that on Windows it isn't possible (yet) to retrieve IPv6 ``gateways()`` method doesn't produce the expected results. It's quite
addresses. I don't use Windows at the moment, so this isn't a priority for complicated extracting this information from the operating system (whichever
me. If you know how to fix it, drop me a line and I'll consider adding any operating system we're talking about), and so I expect there's at least one
necessary code. system out there where this just won't work.
3. This is great! What platforms does it work on?
--------------------------------------------------
It gets regular testing on OS X, Linux and Windows. It has also been used
successfully on Solaris, and it's expected to work properly on other UNIX-like
systems as well. If you are running something that is not supported, and
wish to contribute a patch, please use BitBucket to send a pull request.
4. What license is this under? 4. What license is this under?
------------------------------ ------------------------------
It's an MIT-style license. Here goes: It's an MIT-style license. Here goes:
Copyright (c) 2007, 2008 Alastair Houghton Copyright (c) 2007-2014 Alastair Houghton
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal
...@@ -153,4 +182,13 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE ...@@ -153,4 +182,13 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 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 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. SOFTWARE.
\ No newline at end of file
5. Why the jump to 0.10.0?
--------------------------
Because someone released a fork of netifaces with the version 0.9.0.
Hopefully skipping the version number should remove any confusion. In
addition starting with 0.10.0 Python 3 is now supported and other
features/bugfixes have been included as well. See the CHANGELOG for a
more complete list of changes.
This diff is collapsed.
This diff is collapsed.
README README.rst
netifaces.c netifaces.c
setup.cfg
setup.py setup.py
netifaces.egg-info/PKG-INFO netifaces.egg-info/PKG-INFO
netifaces.egg-info/SOURCES.txt netifaces.egg-info/SOURCES.txt
netifaces.egg-info/dependency_links.txt netifaces.egg-info/dependency_links.txt
netifaces.egg-info/native_libs.txt
netifaces.egg-info/top_level.txt netifaces.egg-info/top_level.txt
netifaces.egg-info/zip-safe
\ No newline at end of file
File mode changed from 100755 to 100644
File mode changed from 100755 to 100644
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment