Skip to main content

Cross-platform network interface and IP address enumeration library

Project description

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 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 2.7 and 3.5+.

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.

Changelog

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ifaddr-0.1.7.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

ifaddr-0.1.7-py2.py3-none-any.whl (10.8 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file ifaddr-0.1.7.tar.gz.

File metadata

  • Download URL: ifaddr-0.1.7.tar.gz
  • Upload date:
  • Size: 9.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Python-urllib/3.8

File hashes

Hashes for ifaddr-0.1.7.tar.gz
Algorithm Hash digest
SHA256 1f9e8a6ca6f16db5a37d3356f07b6e52344f6f9f7e806d618537731669eb1a94
MD5 97c4eb7505643b5f1fe17733cb42abd9
BLAKE2b-256 3dfc4ce147e3997cd0ea470ad27112087545cf83bf85015ddb3054673cb471bb

See more details on using hashes here.

File details

Details for the file ifaddr-0.1.7-py2.py3-none-any.whl.

File metadata

  • Download URL: ifaddr-0.1.7-py2.py3-none-any.whl
  • Upload date:
  • Size: 10.8 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Python-urllib/3.8

File hashes

Hashes for ifaddr-0.1.7-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 d1f603952f0a71c9ab4e705754511e4e03b02565bc4cec7188ad6415ff534cd3
MD5 6c974d3e2ecffb0b6fd3dff6ea12469e
BLAKE2b-256 920fa577a724c03982b800232713874e805c8fcc14f4a2c3060902ed20b50da8

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page