hosts-resolver (1.1.0)

Published 2023-06-17 23:09:16 +02:00 by HorlogeSkynet in HorlogeSkynet/hosts_resolver

Installation

pip install --index-url  hosts-resolver

About this package

Zero-dependency Python module to resolve names using /etc/hosts alone

hosts_resolver

Zero-dependency Python module to resolve names using /etc/hosts alone

Rationale

Sometimes we only want to resolve names using /etc/hosts entries without performing DNS requests (thus socket.getaddrinfo is out of the equation).

So there are three options :

  • manually parse /etc/hosts
  • call getent program and parse its output
  • use this module (which binds libc gethostent function) !

Limitations

  • gethostent is not reentrant (see GETHOSTBYNAME(3))
  • gethostent is not thread-safe (see GETHOSTBYNAME(3))
  • glibc implementations does not support IPv6 addresses (see GETHOSTBYNAME(3))
  • behavior is undefined when using multiple context managers simultaneously

Installation

pip3 install --index-url https://git.forestier.app/api/packages/HorlogeSkynet/pypi/simple/ hosts-resolver

# or manually download latest Wheel and then :
pip3 install ./hosts_resolver-*-py3-none-any.whl

Usage

From API

from hosts_resolver.hosts_resolver import get_hosts_resolver

with get_hosts_resolver() as hosts_resolver:
    print(hosts_resolver.resolve("localhost"))

# -> IPv4Address('127.0.0.1')

From CLI

Why bother ?? You should be looking at getent !

hosts_resolver -j localhost
# -> {"localhost": "127.0.0.1"}

Development

pip3 install -r requirements-dev.txt

pylint src/
mypy src/
isort --check src/
black --check src/

python3 -m build

Requirements

Requires Python: >=3.6
Details
PyPI
2023-06-17 23:09:16 +02:00
50
MIT
11 KiB
Assets (2)
Versions (2) View all
1.1.0 2023-06-17
1.0.0 2023-06-13