python-netifaces
Port variant py37
Summary Portable network interface information (PY37)
Package version 0.10.9
Homepage https://github.com/al45tair/netifaces
Keywords python
Maintainer Python Automaton
License Not yet specified
Other variants py38
Ravenports Buildsheet | History
Ravensource Port Directory | History
Last modified 21 APR 2020, 22:22:44 UTC
Port created 21 APR 2020, 22:22:44 UTC
Subpackage Descriptions
single netifaces 0.10.8 ================ +-------------+------------------+ | Linux/macOS | |BuildStatus| | +-------------+------------------+ | Windows | |WinBuildStatus| | +-------------+------------------+ :alt: Build Status (Linux/Mac) :alt: Build Status (Windows) 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.10.8.tar.gz cd netifaces-0.10.8 python setup.py install **Note that you will need the relevant developer tools for your platform**, as netifaces is written in C and installing this way will compile the extension. 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,
Configuration Switches (platform-specific settings discarded)
PY37 ON Build using Python 3.7 PY38 OFF Build using Python 3.8
Package Dependencies by Type
Build and Runtime python37:single:standard
python-setuptools:single:py37
Download groups
main mirror://PYPI/n/netifaces
Distribution File Information
2dee9ffdd16292878336a58d04a20f0ffe95555465fee7c9bd23b3490ef2abf3 28844 netifaces-0.10.9.tar.gz
Ports that require python-netifaces:py37
No other ports depend on this one.