PKG-INFO 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. Metadata-Version: 2.1
  2. Name: netifaces
  3. Version: 0.11.0
  4. Summary: Portable network interface information.
  5. Home-page: https://github.com/al45tair/netifaces
  6. Author: Alastair Houghton
  7. Author-email: alastair@alastairs-place.net
  8. License: MIT License
  9. Platform: UNKNOWN
  10. Classifier: Development Status :: 4 - Beta
  11. Classifier: Intended Audience :: Developers
  12. Classifier: License :: OSI Approved :: MIT License
  13. Classifier: Topic :: System :: Networking
  14. Classifier: Programming Language :: Python
  15. Classifier: Programming Language :: Python :: 2
  16. Classifier: Programming Language :: Python :: 2.7
  17. Classifier: Programming Language :: Python :: 3
  18. Classifier: Programming Language :: Python :: 3.4
  19. Classifier: Programming Language :: Python :: 3.5
  20. Classifier: Programming Language :: Python :: 3.6
  21. Classifier: Programming Language :: Python :: 3.7
  22. Classifier: Programming Language :: Python :: 3.8
  23. License-File: LICENSE
  24. netifaces 0.10.8
  25. ================
  26. +-------------+------------------+
  27. | Linux/macOS | |BuildStatus| |
  28. +-------------+------------------+
  29. | Windows | |WinBuildStatus| |
  30. +-------------+------------------+
  31. .. |BuildStatus| image:: https://travis-ci.org/al45tair/netifaces.svg?branch=master
  32. :target: https://travis-ci.org/al45tair/netifaces
  33. :alt: Build Status (Linux/Mac)
  34. .. |WinBuildStatus| image:: https://ci.appveyor.com/api/projects/status/3ctn1bl0aigpfjoo/branch/master?svg=true
  35. :target: https://ci.appveyor.com/project/al45tair/netifaces/branch/master
  36. :alt: Build Status (Windows)
  37. .. warning::
  38. netifaces needs a new maintainer. al45tair is no longer able to maintain it
  39. or make new releases due to work commitments.
  40. 1. What is this?
  41. ----------------
  42. It's been annoying me for some time that there's no easy way to get the
  43. address(es) of the machine's network interfaces from Python. There is
  44. a good reason for this difficulty, which is that it is virtually impossible
  45. to do so in a portable manner. However, it seems to me that there should
  46. be a package you can easy_install that will take care of working out the
  47. details of doing so on the machine you're using, then you can get on with
  48. writing Python code without concerning yourself with the nitty gritty of
  49. system-dependent low-level networking APIs.
  50. This package attempts to solve that problem.
  51. 2. How do I use it?
  52. -------------------
  53. First you need to install it, which you can do by typing::
  54. tar xvzf netifaces-0.10.8.tar.gz
  55. cd netifaces-0.10.8
  56. python setup.py install
  57. **Note that you will need the relevant developer tools for your platform**,
  58. as netifaces is written in C and installing this way will compile the extension.
  59. Once that's done, you'll need to start Python and do something like the
  60. following::
  61. >>> import netifaces
  62. Then if you enter
  63. >>> netifaces.interfaces()
  64. ['lo0', 'gif0', 'stf0', 'en0', 'en1', 'fw0']
  65. you'll see the list of interface identifiers for your machine.
  66. You can ask for the addresses of a particular interface by doing
  67. >>> netifaces.ifaddresses('lo0')
  68. {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'}]}
  69. Hmmmm. That result looks a bit cryptic; let's break it apart and explain
  70. what each piece means. It returned a dictionary, so let's look there first::
  71. { 18: [...], 2: [...], 30: [...] }
  72. Each of the numbers refers to a particular address family. In this case, we
  73. have three address families listed; on my system, 18 is ``AF_LINK`` (which means
  74. the link layer interface, e.g. Ethernet), 2 is ``AF_INET`` (normal Internet
  75. addresses), and 30 is ``AF_INET6`` (IPv6).
  76. But wait! Don't use these numbers in your code. The numeric values here are
  77. system dependent; fortunately, I thought of that when writing netifaces, so
  78. the module declares a range of values that you might need. e.g.
  79. >>> netifaces.AF_LINK
  80. 18
  81. Again, on your system, the number may be different.
  82. So, what we've established is that the dictionary that's returned has one
  83. entry for each address family for which this interface has an address. Let's
  84. take a look at the ``AF_INET`` addresses now:
  85. >>> addrs = netifaces.ifaddresses('lo0')
  86. >>> addrs[netifaces.AF_INET]
  87. [{'peer': '127.0.0.1', 'netmask': '255.0.0.0', 'addr': '127.0.0.1'}]
  88. You might be wondering why this value is a list. The reason is that it's
  89. possible for an interface to have more than one address, even within the
  90. same family. I'll say that again: *you can have more than one address of
  91. the same type associated with each interface*.
  92. *Asking for "the" address of a particular interface doesn't make sense.*
  93. Right, so, we can see that this particular interface only has one address,
  94. and, because it's a loopback interface, it's point-to-point and therefore
  95. has a *peer* address rather than a broadcast address.
  96. Let's look at a more interesting interface.
  97. >>> addrs = netifaces.ifaddresses('en0')
  98. >>> addrs[netifaces.AF_INET]
  99. [{'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'}]
  100. This interface has two addresses (see, I told you...) Both of them are
  101. regular IPv4 addresses, although in one case the netmask has been changed
  102. from its default. The netmask *may not* appear on your system if it's set
  103. to the default for the address range.
  104. Because this interface isn't point-to-point, it also has broadcast addresses.
  105. Now, say we want, instead of the IP addresses, to get the MAC address; that
  106. is, the hardware address of the Ethernet adapter running this interface. We
  107. can do
  108. >>> addrs[netifaces.AF_LINK]
  109. [{'addr': '00:12:34:56:78:9a'}]
  110. Note that this may not be available on platforms without getifaddrs(), unless
  111. they happen to implement ``SIOCGIFHWADDR``. Note also that you just get the
  112. address; it's unlikely that you'll see anything else with an ``AF_LINK`` address.
  113. Oh, and don't assume that all ``AF_LINK`` addresses are Ethernet; you might, for
  114. instance, be on a Mac, in which case:
  115. >>> addrs = netifaces.ifaddresses('fw0')
  116. >>> addrs[netifaces.AF_LINK]
  117. [{'addr': '00:12:34:56:78:9a:bc:de'}]
  118. No, that isn't an exceptionally long Ethernet MAC address---it's a FireWire
  119. address.
  120. As of version 0.10.0, you can also obtain a list of gateways on your
  121. machine:
  122. >>> netifaces.gateways()
  123. {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') }}
  124. This dictionary is keyed on address family---in this case, ``AF_INET``---and
  125. each entry is a list of gateways as ``(address, interface, is_default)`` tuples.
  126. Notice that here we have two separate gateways for IPv4 (``AF_INET``); some
  127. operating systems support configurations like this and can either route packets
  128. based on their source, or based on administratively configured routing tables.
  129. For convenience, we also allow you to index the dictionary with the special
  130. value ``'default'``, which returns a dictionary mapping address families to the
  131. default gateway in each case. Thus you can get the default IPv4 gateway with
  132. >>> gws = netifaces.gateways()
  133. >>> gws['default'][netifaces.AF_INET]
  134. ('10.0.1.1', 'en0')
  135. Do note that there may be no default gateway for any given address family;
  136. this is currently very common for IPv6 and much less common for IPv4 but it
  137. can happen even for ``AF_INET``.
  138. BTW, if you're trying to configure your machine to have multiple gateways for
  139. the same address family, it's a very good idea to check the documentation for
  140. your operating system *very* carefully, as some systems become extremely
  141. confused or route packets in a non-obvious manner.
  142. I'm very interested in hearing from anyone (on any platform) for whom the
  143. ``gateways()`` method doesn't produce the expected results. It's quite
  144. complicated extracting this information from the operating system (whichever
  145. operating system we're talking about), and so I expect there's at least one
  146. system out there where this just won't work.
  147. 3. This is great! What platforms does it work on?
  148. --------------------------------------------------
  149. It gets regular testing on OS X, Linux and Windows. It has also been used
  150. successfully on Solaris, and it's expected to work properly on other UNIX-like
  151. systems as well. If you are running something that is not supported, and
  152. wish to contribute a patch, please use Github to send a pull request.
  153. 4. What license is this under?
  154. ------------------------------
  155. It's an MIT-style license. See `LICENSE <./LICENSE>`_.
  156. 5. Why the jump to 0.10.0?
  157. --------------------------
  158. Because someone released a fork of netifaces with the version 0.9.0.
  159. Hopefully skipping the version number should remove any confusion. In
  160. addition starting with 0.10.0 Python 3 is now supported and other
  161. features/bugfixes have been included as well. See the CHANGELOG for a
  162. more complete list of changes.