Skip to main content

Module and script to check if local machine is on agiven network.

Project description

Module and script to test local network membership (IPv4)
===========================================================

A set of utility functions and a command-line script useful in testing local
machine membership in IPv4 networks. Requires no external modules
("batteries-included" only).

Command-line usage
++++++++++++++++++

#. Sample usage

Test all network interfaces, and return success if any interface has an IP
address in the 10.100.3.0/24 network:

.. code-block:: bash

user@localhost$ local_net 10.100.3.0/24; echo $?
0
user@localhost$

Specific interfaces may be tested by inclusion of the -i/--iface flag, which
may be repeated:

.. code-block:: bash

user@localhost$ local_net -i etho -i wlan2 192.168.1.0/24

Asserting that no local interface is a member of a given network is also
possible by using the -n/--negate flag:

.. code-block:: bash

user@localhost$ local_net -n 10.1.0.0/16


Test success or failure is indicated by exit status code - 0 for success, 1
for failure. This allows for ease of use in conditional statements and other
tests (e.g. ssh config 'exec' testing). Exit status 64 is returned if an
unrecoverable error occurs (e.g. an interface was passed that does not exist),
and error information may be written to stderr. Otherwise, no output is made.


Requirements and compatibility
++++++++++++++++++++++++++++++

The code should work on any POSIX-compatible system, but has only been tested
on modern Linux installs. Pull requests and bug reports for other operating
systems are welcome. Supports Python versions 2.6+. Python versions < 3.3
require a system libc which supports if_nameindex() to get around lack of same
in socket module.

=========
Changelog
=========
All notable changes to this project will be documented in this file.

The format is based on `Keep a Changelog <https://keepachangelog.com/en/1.0.0/>`_,
and this project adheres to `Semantic Versioning <https://semver.org/spec/v2.0.0.html>`_.

[0.2.0] - 2018-09-30
++++++++++++++++++++

Changed
-------

- Don't import ctypes until we need it.
- Catch exception from all_ifaces() in _main so we can exit correctly.
- Add LICENSE file
- Fix this CHANGELOG

[0.1.0] - 2018-09-30
++++++++++++++++++++

Added
-----

- CHANGELOG.rst
- MANIFEST.in
- README.rst
- localnet.py
- setup.cfg
- setup.py
- .gitignore


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

localnet-0.2.0.tar.gz (5.6 kB view hashes)

Uploaded Source

Built Distribution

localnet-0.2.0-py3-none-any.whl (17.7 kB view hashes)

Uploaded Python 3

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