Skip to main content
https://github.com/pydron/ifaddr/workflows/CI/badge.svg https://img.shields.io/pypi/v/ifaddr.svg https://codecov.io/gh/pydron/ifaddr/branch/master/graph/badge.svg

ifaddr is a small Python library that allows you to find all the Ethernet and IP addresses of the computer. It is tested on Linux, OS X, and Windows. Other BSD derivatives like OpenBSD, FreeBSD, and NetBSD should work too, but I haven’t personally tested those. Solaris/Illumos should also work.

This library is open source and released under the MIT License. It works with Python 3.7+.

You can install it with pip install ifaddr. It doesn’t need to compile anything, so there shouldn’t be any surprises. Even on Windows.

Project links:

Let’s get going!

import ifaddr

adapters = ifaddr.get_adapters()

for adapter in adapters:
    print("IPs of network adapter " + adapter.nice_name)
    for ip in adapter.ips:
        print("   %s/%s" % (ip.ip, ip.network_prefix))

This will print:

IPs of network adapter H5321 gw Mobile Broadband Driver
   IP ('fe80::9:ebdf:30ab:39a3', 0L, 17L)/64
   IP 169.254.57.163/16
IPs of network adapter Intel(R) Centrino(R) Advanced-N 6205
   IP ('fe80::481f:3c9d:c3f6:93f8', 0L, 12L)/64
   IP 192.168.0.51/24
IPs of network adapter Intel(R) 82579LM Gigabit Network Connection
   IP ('fe80::85cd:e07e:4f7a:6aa6', 0L, 11L)/64
   IP 192.168.0.53/24
IPs of network adapter Software Loopback Interface 1
   IP ('::1', 0L, 0L)/128
   IP 127.0.0.1/8

You get both IPv4 and IPv6 addresses. The later complete with flowinfo and scope_id.

If you wish to include network interfaces that do not have a configured IP addresss, pass the include_unconfigured parameter to get_adapters(). Adapters with no configured IP addresses will have an zero-length ips property. For example:

import ifaddr

adapters = ifaddr.get_adapters(include_unconfigured=True)

for adapter in adapters:
    print("IPs of network adapter " + adapter.nice_name)
    if adapter.ips:
        for ip in adapter.ips:
            print("   %s/%s" % (ip.ip, ip.network_prefix))
    else:
        print("  No IPs configured")

Changelog

0.2.0

  • Added an option to include IP-less adapters, thanks to memory

  • Fixed a bug where an interface’s name was bytes, not str, on Windows

  • Added an implementation of netifaces.interfaces() (available through ifaddr.netifaces.interfaces())

  • Added type hints

Backwards incompatible/breaking changes:

  • Dropped Python 3.6 support

0.1.7

  • Fixed Python 3 compatibility in the examples, thanks to Tristan Stenner and Josef Schlehofer

  • Exposed network interface indexes in Adapter.index, thanks to Dmitry Tantsur

  • Added the license file to distributions on PyPI, thanks to Tomáš Chvátal

  • Fixed Illumos/Solaris compatibility based on a patch proposed by Jorge Schrauwen

  • Set up universal wheels, ifaddr will have both source and wheel distributions on PyPI from now on

Alternatives

Alastair Houghton develops netifaces which can do everything this library can, and more. The only drawback is that it needs to be compiled, which can make the installation difficult.

As of ifaddr 0.2.0 we implement the equivalent of netifaces.interfaces(). It’s available through ifaddr.netifaces.interfaces().

Release files for ifaddr 0.2.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 ifaddr 0.2.0
File Size Uploaded
ifaddr-0.2.0.tar.gz 10.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ifaddr 0.2.0
File Interpreter ABI Platform
ifaddr-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 22.8 kB

Release files / ifaddr-0.2.0.tar.gz

Download URL ifaddr-0.2.0.tar.gz
Size 10.5 kB
Tags Source
SHA-256 checksum
How to use checksums
cc0cbfcaabf765d44595825fb96a99bb12c79716b73b44330ea38ee2b0c4aed4
BLAKE2b-256 checksum
How to use checksums
e8acfb4c578f4a3256561548cd825646680edcadb9440f3f68add95ade1eb791
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.4

Release files / ifaddr-0.2.0-py3-none-any.whl

Download URL ifaddr-0.2.0-py3-none-any.whl
Size 12.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
085e0305cfe6f16ab12d72e2024030f5d52674afad6911bb1eee207177b8a748
BLAKE2b-256 checksum
How to use checksums
9c1f19ebc343cc71a7ffa78f17018535adc5cbdd87afb31d7c34874680148b32
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.4

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.7

2 release files

0.1.6

1 release file

0.1.5

1 release file

0.1.4

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1.0

1 release file

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