icmplib


Nameicmplib JSON
Version 3.0.4 PyPI version JSON
download
home_pagehttps://github.com/ValentinBELYN/icmplib
SummaryEasily forge ICMP packets and make your own ping and traceroute.
upload_time2023-10-10 17:05:12
maintainer
docs_urlNone
authorValentin BELYN
requires_python>=3.7
licenseGNU Lesser General Public License v3.0
keywords icmp sockets ping multiping traceroute async asyncio ipv4 ipv6 python python3
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <br>
<img src="https://raw.githubusercontent.com/ValentinBELYN/icmplib/main/media/icmplib-logo.png" height="125" width="100" alt="icmplib">
<br>

icmplib is a brand new and modern implementation of the ICMP protocol in Python.<br>
Use the built-in functions or build your own, you have the choice!

<br>

## Features

- 🌳 **Ready-to-use:** icmplib offers ready-to-use functions such as the most popular ones: `ping`, `multiping` and `traceroute`. An extensive documentation also helps you get started.
- 💎 **Modern:** This library uses the latest mechanisms offered by Python 3.7+ and is fully object-oriented.
- 🚀 **Fast:** Each class and function has been designed and optimized to deliver the best performance. Some functions are also asynchronous like the `async_ping` and `async_multiping` functions. You can ping the world in seconds!
- ⚡️ **Powerful:** Use the library without root privileges, set the traffic class of ICMP packets, customize their payload, send broadcast requests and more!
- 🔩 **Evolutive:** Easily build your own classes and functions with `ICMPv4` and `ICMPv6` sockets.
- 🔥 **Seamless integration of IPv6:** Use IPv6 the same way you use IPv4.
- 🍺 **Cross-platform:** Optimized for Linux, macOS and Windows. The library automatically manages the specificities of each system.
- 🤘 **No dependency:** icmplib is a pure Python implementation of the ICMP protocol. It does not rely on any external dependency.

<br>

## Installation

- **Install icmplib**

  The recommended way to install icmplib is to use `pip3`:

  ```shell
  $ pip3 install icmplib
  ```

- **Import basic functions**

  ```python
  from icmplib import ping, multiping, traceroute, resolve
  ```

- **Import asynchronous functions**

  ```python
  from icmplib import async_ping, async_multiping, async_resolve
  ```

- **Import sockets (advanced)**

  ```python
  from icmplib import ICMPv4Socket, ICMPv6Socket, AsyncSocket, ICMPRequest, ICMPReply
  ```

- **Import exceptions**

  ```python
  from icmplib import ICMPLibError, NameLookupError, ICMPSocketError
  from icmplib import SocketAddressError, SocketPermissionError
  from icmplib import SocketUnavailableError, SocketBroadcastError, TimeoutExceeded
  from icmplib import ICMPError, DestinationUnreachable, TimeExceeded
  ```

  *Import only what you need.*

<br>

## Getting started

### ping

Send ICMP Echo Request packets to a network host.

```python
ping(address, count=4, interval=1, timeout=2, id=None, source=None, family=None, privileged=True, **kwargs)
```

#### Parameters

- `address`

  The IP address, hostname or FQDN of the host to which messages should be sent. For deterministic behavior, prefer to use an IP address.

  - Type: `str`

- `count`

  The number of ping to perform.

  - Type: `int`
  - Default: `4`

- `interval`

  The interval in seconds between sending each packet.

  - Type: `int` or `float`
  - Default: `1`

- `timeout`

  The maximum waiting time for receiving a reply in seconds.

  - Type: `int` or `float`
  - Default: `2`

- `id`

  The identifier of ICMP requests. Used to match the responses with requests. In practice, a unique identifier should be used for every ping process. On Linux, this identifier is ignored when the `privileged` parameter is disabled. The library handles this identifier itself by default.

  - Type: `int`
  - Default: `None`

- `source`

  The IP address from which you want to send packets. By default, the interface is automatically chosen according to the specified destination.

  - Type: `str`
  - Default: `None`

- `family`

  The address family if a hostname or FQDN is specified. Can be set to `4` for IPv4 or `6` for IPv6 addresses. By default, this function searches for IPv4 addresses first before searching for IPv6 addresses.

  - Type: `int`
  - Default: `None`

- `privileged`

  When this option is enabled, this library fully manages the exchanges and the structure of ICMP packets. Disable this option if you want to use this function without root privileges and let the kernel handle ICMP headers.

  [Learn more about the `privileged` parameter.](https://github.com/ValentinBELYN/icmplib/blob/main/docs/6-use-icmplib-without-privileges.md)

  *Only available on Unix systems. Ignored on Windows.*

  - Type: `bool`
  - Default: `True`

- `payload`

  The payload content in bytes. A random payload is used by default.

  - Type: `bytes`
  - Default: `None`

- `payload_size`

  The payload size. Ignored when the `payload` parameter is set.

  - Type: `int`
  - Default: `56`

- `traffic_class`

  The traffic class of ICMP packets. Provides a defined level of service to packets by setting the DS Field (formerly TOS) or the Traffic Class field of IP headers. Packets are delivered with the minimum priority by default (Best-effort delivery). Intermediate routers must be able to support this feature.

  *Only available on Unix systems. Ignored on Windows.*

  - Type: `int`
  - Default: `0`

#### Return value

- A `Host` object containing statistics about the desired destination:<br>
  `address`, `min_rtt`, `avg_rtt`, `max_rtt`, `rtts`, `packets_sent`, `packets_received`, `packet_loss`, `jitter`, `is_alive`

#### Exceptions

- `NameLookupError`

  If you pass a hostname or FQDN in parameters and it does not exist or cannot be resolved.

- `SocketPermissionError`

  If the privileges are insufficient to create the socket.

- `SocketAddressError`

  If the source address cannot be assigned to the socket.

- `ICMPSocketError`

  If another error occurs. See the `ICMPv4Socket` or `ICMPv6Socket` class for details.

#### Example

```python
>>> from icmplib import ping

>>> host = ping('1.1.1.1', count=10, interval=0.2)

>>> host.address              # The IP address of the host that responded
'1.1.1.1'                     # to the request

>>> host.min_rtt              # The minimum round-trip time in milliseconds
5.761

>>> host.avg_rtt              # The average round-trip time in milliseconds
12.036

>>> host.max_rtt              # The maximum round-trip time in milliseconds
16.207

>>> host.rtts                 # The list of round-trip times expressed in
[ 11.595, 13.135, 9.614,      # milliseconds
  16.018, 11.960, 5.761,      # The results are not rounded unlike other
  16.207, 11.937, 12.098 ]    # properties

>>> host.packets_sent         # The number of requests transmitted to the
10                            # remote host

>>> host.packets_received     # The number of ICMP responses received from
9                             # the remote host

>>> host.packet_loss          # Packet loss occurs when packets fail to
0.1                           # reach their destination. Returns a float
                              # between 0 and 1 (all packets are lost)

>>> host.jitter               # The jitter in milliseconds, defined as the
4.575                         # variance of the latency of packets flowing
                              # through the network

>>> host.is_alive             # Indicates whether the host is reachable
True
```

<br>

### multiping

Send ICMP Echo Request packets to several network hosts.

```python
multiping(addresses, count=2, interval=0.5, timeout=2, concurrent_tasks=50, source=None, family=None, privileged=True, **kwargs)
```

#### Parameters

- `addresses`

  The IP addresses of the hosts to which messages should be sent. Hostnames and FQDNs are allowed but not recommended. You can easily retrieve their IP address by calling the built-in `resolve` function.

  - Type: `list[str]`

- `count`

  The number of ping to perform per address.

  - Type: `int`
  - Default: `2`

- `interval`

  The interval in seconds between sending each packet.

  - Type: `int` or `float`
  - Default: `0.5`

- `timeout`

  The maximum waiting time for receiving a reply in seconds.

  - Type: `int` or `float`
  - Default: `2`

- `concurrent_tasks`

  The maximum number of concurrent tasks to speed up processing. This value cannot exceed the maximum number of file descriptors configured on the operating system.

  - Type: `int`
  - Default: `50`

- `source`

  The IP address from which you want to send packets. By default, the interface is automatically chosen according to the specified destinations. This parameter should not be used if you are passing both IPv4 and IPv6 addresses to this function.

  - Type: `str`
  - Default: `None`

- `family`

  The address family if a hostname or FQDN is specified. Can be set to `4` for IPv4 or `6` for IPv6 addresses. By default, this function searches for IPv4 addresses first before searching for IPv6 addresses.

  - Type: `int`
  - Default: `None`

- `privileged`

  When this option is enabled, this library fully manages the exchanges and the structure of ICMP packets. Disable this option if you want to use this function without root privileges and let the kernel handle ICMP headers.

  [Learn more about the `privileged` parameter.](https://github.com/ValentinBELYN/icmplib/blob/main/docs/6-use-icmplib-without-privileges.md)

  *Only available on Unix systems. Ignored on Windows.*

  - Type: `bool`
  - Default: `True`

- `payload`

  The payload content in bytes. A random payload is used by default.

  - Type: `bytes`
  - Default: `None`

- `payload_size`

  The payload size. Ignored when the `payload` parameter is set.

  - Type: `int`
  - Default: `56`

- `traffic_class`

  The traffic class of ICMP packets. Provides a defined level of service to packets by setting the DS Field (formerly TOS) or the Traffic Class field of IP headers. Packets are delivered with the minimum priority by default (Best-effort delivery). Intermediate routers must be able to support this feature.

  *Only available on Unix systems. Ignored on Windows.*

  - Type: `int`
  - Default: `0`

#### Return value

- A list of `Host` objects containing statistics about the desired destinations:<br>
  `address`, `min_rtt`, `avg_rtt`, `max_rtt`, `rtts`, `packets_sent`, `packets_received`, `packet_loss`, `jitter`, `is_alive`

  The list is sorted in the same order as the addresses passed in parameters.

#### Exceptions

- `NameLookupError`

  If you pass a hostname or FQDN in parameters and it does not exist or cannot be resolved.

- `SocketPermissionError`

  If the privileges are insufficient to create the socket.

- `SocketAddressError`

  If the source address cannot be assigned to the socket.

- `ICMPSocketError`

  If another error occurs. See the `ICMPv4Socket` or `ICMPv6Socket` class for details.

#### Example

```python
>>> from icmplib import multiping

>>> hosts = multiping(['10.0.0.5', '127.0.0.1', '::1'])

>>> for host in hosts:
...     if host.is_alive:
...         # See the Host class for details
...         print(f'{host.address} is up!')
...     else:
...         print(f'{host.address} is down!')

# 10.0.0.5 is down!
# 127.0.0.1 is up!
# ::1 is up!
```

<br>

### traceroute

Determine the route to a destination host.

The Internet is a large and complex aggregation of network hardware, connected together by gateways. Tracking the route one's packets follow can be difficult. This function uses the IP protocol time to live field and attempts to elicit an ICMP Time Exceeded response from each gateway along the path to some host.

*This function requires root privileges to run.*

```python
traceroute(address, count=2, interval=0.05, timeout=2, first_hop=1, max_hops=30, fast=False, id=None, source=None, family=None, **kwargs)
```

#### Parameters

- `address`

  The IP address, hostname or FQDN of the host to reach. For deterministic behavior, prefer to use an IP address.

  - Type: `str`

- `count`

  The number of ping to perform per hop.

  - Type: `int`
  - Default: `2`

- `interval`

  The interval in seconds between sending each packet.

  - Type: `int` or `float`
  - Default: `0.05`

- `timeout`

  The maximum waiting time for receiving a reply in seconds.

  - Type: `int` or `float`
  - Default: `2`

- `first_hop`

  The initial time to live value used in outgoing probe packets.

  - Type: `int`
  - Default: `1`

- `max_hops`

  The maximum time to live (max number of hops) used in outgoing probe packets.

  - Type: `int`
  - Default: `30`

- `fast`

  When this option is enabled and an intermediate router has been reached, skip to the next hop rather than perform additional requests. The `count` parameter then becomes the maximum number of requests in the event of no response.

  - Type: `bool`
  - Default: `False`

- `id`

  The identifier of ICMP requests. Used to match the responses with requests. In practice, a unique identifier should be used for every traceroute process. The library handles this identifier itself by default.

  - Type: `int`
  - Default: `None`

- `source`

  The IP address from which you want to send packets. By default, the interface is automatically chosen according to the specified destination.

  - Type: `str`
  - Default: `None`

- `family`

  The address family if a hostname or FQDN is specified. Can be set to `4` for IPv4 or `6` for IPv6 addresses. By default, this function searches for IPv4 addresses first before searching for IPv6 addresses.

  - Type: `int`
  - Default: `None`

- `payload`

  The payload content in bytes. A random payload is used by default.

  - Type: `bytes`
  - Default: `None`

- `payload_size`

  The payload size. Ignored when the `payload` parameter is set.

  - Type: `int`
  - Default: `56`

- `traffic_class`

  The traffic class of ICMP packets. Provides a defined level of service to packets by setting the DS Field (formerly TOS) or the Traffic Class field of IP headers. Packets are delivered with the minimum priority by default (Best-effort delivery). Intermediate routers must be able to support this feature.

  *Only available on Unix systems. Ignored on Windows.*

  - Type: `int`
  - Default: `0`

#### Return value

- A list of `Hop` objects representing the route to the desired destination. A `Hop` has the same properties as a `Host` object but it also has a `distance`:<br>
  `address`, `min_rtt`, `avg_rtt`, `max_rtt`, `rtts`, `packets_sent`, `packets_received`, `packet_loss`, `jitter`, `is_alive`, `distance`

  The list is sorted in ascending order according to the distance, in terms of hops, that separates the remote host from the current machine. Gateways that do not respond to requests are not added to this list.

#### Exceptions

- `NameLookupError`

  If you pass a hostname or FQDN in parameters and it does not exist or cannot be resolved.

- `SocketPermissionError`

  If the privileges are insufficient to create the socket.

- `SocketAddressError`

  If the source address cannot be assigned to the socket.

- `ICMPSocketError`

  If another error occurs. See the `ICMPv4Socket` or `ICMPv6Socket` class for details.

#### Example

```python
>>> from icmplib import traceroute

>>> hops = traceroute('1.1.1.1')

>>> print('Distance/TTL    Address    Average round-trip time')
>>> last_distance = 0

>>> for hop in hops:
...     if last_distance + 1 != hop.distance:
...         print('Some gateways are not responding')
...
...     # See the Hop class for details
...     print(f'{hop.distance}    {hop.address}    {hop.avg_rtt} ms')
...
...     last_distance = hop.distance

# Distance/TTL    Address                 Average round-trip time
# 1               10.0.0.1                5.196 ms
# 2               194.149.169.49          7.552 ms
# 3               194.149.166.54          12.21 ms
# *               Some gateways are not responding
# 5               212.73.205.22           22.15 ms
# 6               1.1.1.1                 13.59 ms
```

<br>

### async_ping

Send ICMP Echo Request packets to a network host.

*This function is non-blocking.*

```python
async_ping(address, count=4, interval=1, timeout=2, id=None, source=None, family=None, privileged=True, **kwargs)
```

#### Parameters, return value and exceptions

The same parameters, return value and exceptions as for the `ping` function.

#### Example

```python
>>> import asyncio
>>> from icmplib import async_ping

>>> async def is_alive(address):
...     host = await async_ping(address, count=10, interval=0.2)
...     return host.is_alive

>>> asyncio.run(is_alive('1.1.1.1'))
True
```

<br>

### async_multiping

Send ICMP Echo Request packets to several network hosts.

*This function is non-blocking.*

```python
async_multiping(addresses, count=2, interval=0.5, timeout=2, concurrent_tasks=50, source=None, family=None, privileged=True, **kwargs)
```

#### Parameters, return value and exceptions

The same parameters, return values and exceptions as for the `multiping` function.

#### Example

```python
>>> import asyncio
>>> from icmplib import async_multiping

>>> async def are_alive(*addresses):
...     hosts = await async_multiping(addresses)
...     
...     for host in hosts:
...         if not host.is_alive:
...             return False
...
...     return True

>>> asyncio.run(are_alive('10.0.0.5', '127.0.0.1', '::1'))
False
```

<br>

## Documentation

This page only gives an overview of the features of icmplib.

To learn more about the built-in functions, on how to create your own and handle exceptions, you can click on the following link:

- 🚀 [Documentation](https://github.com/ValentinBELYN/icmplib/tree/main/docs)

## Contributing

Comments and enhancements are welcome.

All development is done on [GitHub](https://github.com/ValentinBELYN/icmplib). Use [Issues](https://github.com/ValentinBELYN/icmplib/issues) to report problems and submit feature requests. Please include a minimal example that reproduces the bug.

## Donate

icmplib is completely free and open source. It has been fully developed on my free time. If you enjoy it, please consider donating to support the development.

- 🎉 [Donate via PayPal](https://paypal.me/ValentinBELYN)

## License

Copyright 2017-2023 Valentin BELYN.

Code released under the GNU LGPLv3 license. See the [LICENSE](https://github.com/ValentinBELYN/icmplib/blob/main/LICENSE) for details.



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/ValentinBELYN/icmplib",
    "name": "icmplib",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "icmp,sockets,ping,multiping,traceroute,async,asyncio,ipv4,ipv6,python,python3",
    "author": "Valentin BELYN",
    "author_email": "valentin-hello@gmx.com",
    "download_url": "https://files.pythonhosted.org/packages/6d/78/ca07444be85ec718d4a7617f43fdb5b4eaae40bc15a04a5c888b64f3e35f/icmplib-3.0.4.tar.gz",
    "platform": null,
    "description": "<br>\n<img src=\"https://raw.githubusercontent.com/ValentinBELYN/icmplib/main/media/icmplib-logo.png\" height=\"125\" width=\"100\" alt=\"icmplib\">\n<br>\n\nicmplib is a brand new and modern implementation of the ICMP protocol in Python.<br>\nUse the built-in functions or build your own, you have the choice!\n\n<br>\n\n## Features\n\n- \ud83c\udf33 **Ready-to-use:** icmplib offers ready-to-use functions such as the most popular ones: `ping`, `multiping` and `traceroute`. An extensive documentation also helps you get started.\n- \ud83d\udc8e **Modern:** This library uses the latest mechanisms offered by Python 3.7+ and is fully object-oriented.\n- \ud83d\ude80 **Fast:** Each class and function has been designed and optimized to deliver the best performance. Some functions are also asynchronous like the `async_ping` and `async_multiping` functions. You can ping the world in seconds!\n- \u26a1\ufe0f **Powerful:** Use the library without root privileges, set the traffic class of ICMP packets, customize their payload, send broadcast requests and more!\n- \ud83d\udd29 **Evolutive:** Easily build your own classes and functions with `ICMPv4` and `ICMPv6` sockets.\n- \ud83d\udd25 **Seamless integration of IPv6:** Use IPv6 the same way you use IPv4.\n- \ud83c\udf7a **Cross-platform:** Optimized for Linux, macOS and Windows. The library automatically manages the specificities of each system.\n- \ud83e\udd18 **No dependency:** icmplib is a pure Python implementation of the ICMP protocol. It does not rely on any external dependency.\n\n<br>\n\n## Installation\n\n- **Install icmplib**\n\n  The recommended way to install icmplib is to use `pip3`:\n\n  ```shell\n  $ pip3 install icmplib\n  ```\n\n- **Import basic functions**\n\n  ```python\n  from icmplib import ping, multiping, traceroute, resolve\n  ```\n\n- **Import asynchronous functions**\n\n  ```python\n  from icmplib import async_ping, async_multiping, async_resolve\n  ```\n\n- **Import sockets (advanced)**\n\n  ```python\n  from icmplib import ICMPv4Socket, ICMPv6Socket, AsyncSocket, ICMPRequest, ICMPReply\n  ```\n\n- **Import exceptions**\n\n  ```python\n  from icmplib import ICMPLibError, NameLookupError, ICMPSocketError\n  from icmplib import SocketAddressError, SocketPermissionError\n  from icmplib import SocketUnavailableError, SocketBroadcastError, TimeoutExceeded\n  from icmplib import ICMPError, DestinationUnreachable, TimeExceeded\n  ```\n\n  *Import only what you need.*\n\n<br>\n\n## Getting started\n\n### ping\n\nSend ICMP Echo Request packets to a network host.\n\n```python\nping(address, count=4, interval=1, timeout=2, id=None, source=None, family=None, privileged=True, **kwargs)\n```\n\n#### Parameters\n\n- `address`\n\n  The IP address, hostname or FQDN of the host to which messages should be sent. For deterministic behavior, prefer to use an IP address.\n\n  - Type: `str`\n\n- `count`\n\n  The number of ping to perform.\n\n  - Type: `int`\n  - Default: `4`\n\n- `interval`\n\n  The interval in seconds between sending each packet.\n\n  - Type: `int` or `float`\n  - Default: `1`\n\n- `timeout`\n\n  The maximum waiting time for receiving a reply in seconds.\n\n  - Type: `int` or `float`\n  - Default: `2`\n\n- `id`\n\n  The identifier of ICMP requests. Used to match the responses with requests. In practice, a unique identifier should be used for every ping process. On Linux, this identifier is ignored when the `privileged` parameter is disabled. The library handles this identifier itself by default.\n\n  - Type: `int`\n  - Default: `None`\n\n- `source`\n\n  The IP address from which you want to send packets. By default, the interface is automatically chosen according to the specified destination.\n\n  - Type: `str`\n  - Default: `None`\n\n- `family`\n\n  The address family if a hostname or FQDN is specified. Can be set to `4` for IPv4 or `6` for IPv6 addresses. By default, this function searches for IPv4 addresses first before searching for IPv6 addresses.\n\n  - Type: `int`\n  - Default: `None`\n\n- `privileged`\n\n  When this option is enabled, this library fully manages the exchanges and the structure of ICMP packets. Disable this option if you want to use this function without root privileges and let the kernel handle ICMP headers.\n\n  [Learn more about the `privileged` parameter.](https://github.com/ValentinBELYN/icmplib/blob/main/docs/6-use-icmplib-without-privileges.md)\n\n  *Only available on Unix systems. Ignored on Windows.*\n\n  - Type: `bool`\n  - Default: `True`\n\n- `payload`\n\n  The payload content in bytes. A random payload is used by default.\n\n  - Type: `bytes`\n  - Default: `None`\n\n- `payload_size`\n\n  The payload size. Ignored when the `payload` parameter is set.\n\n  - Type: `int`\n  - Default: `56`\n\n- `traffic_class`\n\n  The traffic class of ICMP packets. Provides a defined level of service to packets by setting the DS Field (formerly TOS) or the Traffic Class field of IP headers. Packets are delivered with the minimum priority by default (Best-effort delivery). Intermediate routers must be able to support this feature.\n\n  *Only available on Unix systems. Ignored on Windows.*\n\n  - Type: `int`\n  - Default: `0`\n\n#### Return value\n\n- A `Host` object containing statistics about the desired destination:<br>\n  `address`, `min_rtt`, `avg_rtt`, `max_rtt`, `rtts`, `packets_sent`, `packets_received`, `packet_loss`, `jitter`, `is_alive`\n\n#### Exceptions\n\n- `NameLookupError`\n\n  If you pass a hostname or FQDN in parameters and it does not exist or cannot be resolved.\n\n- `SocketPermissionError`\n\n  If the privileges are insufficient to create the socket.\n\n- `SocketAddressError`\n\n  If the source address cannot be assigned to the socket.\n\n- `ICMPSocketError`\n\n  If another error occurs. See the `ICMPv4Socket` or `ICMPv6Socket` class for details.\n\n#### Example\n\n```python\n>>> from icmplib import ping\n\n>>> host = ping('1.1.1.1', count=10, interval=0.2)\n\n>>> host.address              # The IP address of the host that responded\n'1.1.1.1'                     # to the request\n\n>>> host.min_rtt              # The minimum round-trip time in milliseconds\n5.761\n\n>>> host.avg_rtt              # The average round-trip time in milliseconds\n12.036\n\n>>> host.max_rtt              # The maximum round-trip time in milliseconds\n16.207\n\n>>> host.rtts                 # The list of round-trip times expressed in\n[ 11.595, 13.135, 9.614,      # milliseconds\n  16.018, 11.960, 5.761,      # The results are not rounded unlike other\n  16.207, 11.937, 12.098 ]    # properties\n\n>>> host.packets_sent         # The number of requests transmitted to the\n10                            # remote host\n\n>>> host.packets_received     # The number of ICMP responses received from\n9                             # the remote host\n\n>>> host.packet_loss          # Packet loss occurs when packets fail to\n0.1                           # reach their destination. Returns a float\n                              # between 0 and 1 (all packets are lost)\n\n>>> host.jitter               # The jitter in milliseconds, defined as the\n4.575                         # variance of the latency of packets flowing\n                              # through the network\n\n>>> host.is_alive             # Indicates whether the host is reachable\nTrue\n```\n\n<br>\n\n### multiping\n\nSend ICMP Echo Request packets to several network hosts.\n\n```python\nmultiping(addresses, count=2, interval=0.5, timeout=2, concurrent_tasks=50, source=None, family=None, privileged=True, **kwargs)\n```\n\n#### Parameters\n\n- `addresses`\n\n  The IP addresses of the hosts to which messages should be sent. Hostnames and FQDNs are allowed but not recommended. You can easily retrieve their IP address by calling the built-in `resolve` function.\n\n  - Type: `list[str]`\n\n- `count`\n\n  The number of ping to perform per address.\n\n  - Type: `int`\n  - Default: `2`\n\n- `interval`\n\n  The interval in seconds between sending each packet.\n\n  - Type: `int` or `float`\n  - Default: `0.5`\n\n- `timeout`\n\n  The maximum waiting time for receiving a reply in seconds.\n\n  - Type: `int` or `float`\n  - Default: `2`\n\n- `concurrent_tasks`\n\n  The maximum number of concurrent tasks to speed up processing. This value cannot exceed the maximum number of file descriptors configured on the operating system.\n\n  - Type: `int`\n  - Default: `50`\n\n- `source`\n\n  The IP address from which you want to send packets. By default, the interface is automatically chosen according to the specified destinations. This parameter should not be used if you are passing both IPv4 and IPv6 addresses to this function.\n\n  - Type: `str`\n  - Default: `None`\n\n- `family`\n\n  The address family if a hostname or FQDN is specified. Can be set to `4` for IPv4 or `6` for IPv6 addresses. By default, this function searches for IPv4 addresses first before searching for IPv6 addresses.\n\n  - Type: `int`\n  - Default: `None`\n\n- `privileged`\n\n  When this option is enabled, this library fully manages the exchanges and the structure of ICMP packets. Disable this option if you want to use this function without root privileges and let the kernel handle ICMP headers.\n\n  [Learn more about the `privileged` parameter.](https://github.com/ValentinBELYN/icmplib/blob/main/docs/6-use-icmplib-without-privileges.md)\n\n  *Only available on Unix systems. Ignored on Windows.*\n\n  - Type: `bool`\n  - Default: `True`\n\n- `payload`\n\n  The payload content in bytes. A random payload is used by default.\n\n  - Type: `bytes`\n  - Default: `None`\n\n- `payload_size`\n\n  The payload size. Ignored when the `payload` parameter is set.\n\n  - Type: `int`\n  - Default: `56`\n\n- `traffic_class`\n\n  The traffic class of ICMP packets. Provides a defined level of service to packets by setting the DS Field (formerly TOS) or the Traffic Class field of IP headers. Packets are delivered with the minimum priority by default (Best-effort delivery). Intermediate routers must be able to support this feature.\n\n  *Only available on Unix systems. Ignored on Windows.*\n\n  - Type: `int`\n  - Default: `0`\n\n#### Return value\n\n- A list of `Host` objects containing statistics about the desired destinations:<br>\n  `address`, `min_rtt`, `avg_rtt`, `max_rtt`, `rtts`, `packets_sent`, `packets_received`, `packet_loss`, `jitter`, `is_alive`\n\n  The list is sorted in the same order as the addresses passed in parameters.\n\n#### Exceptions\n\n- `NameLookupError`\n\n  If you pass a hostname or FQDN in parameters and it does not exist or cannot be resolved.\n\n- `SocketPermissionError`\n\n  If the privileges are insufficient to create the socket.\n\n- `SocketAddressError`\n\n  If the source address cannot be assigned to the socket.\n\n- `ICMPSocketError`\n\n  If another error occurs. See the `ICMPv4Socket` or `ICMPv6Socket` class for details.\n\n#### Example\n\n```python\n>>> from icmplib import multiping\n\n>>> hosts = multiping(['10.0.0.5', '127.0.0.1', '::1'])\n\n>>> for host in hosts:\n...     if host.is_alive:\n...         # See the Host class for details\n...         print(f'{host.address} is up!')\n...     else:\n...         print(f'{host.address} is down!')\n\n# 10.0.0.5 is down!\n# 127.0.0.1 is up!\n# ::1 is up!\n```\n\n<br>\n\n### traceroute\n\nDetermine the route to a destination host.\n\nThe Internet is a large and complex aggregation of network hardware, connected together by gateways. Tracking the route one's packets follow can be difficult. This function uses the IP protocol time to live field and attempts to elicit an ICMP Time Exceeded response from each gateway along the path to some host.\n\n*This function requires root privileges to run.*\n\n```python\ntraceroute(address, count=2, interval=0.05, timeout=2, first_hop=1, max_hops=30, fast=False, id=None, source=None, family=None, **kwargs)\n```\n\n#### Parameters\n\n- `address`\n\n  The IP address, hostname or FQDN of the host to reach. For deterministic behavior, prefer to use an IP address.\n\n  - Type: `str`\n\n- `count`\n\n  The number of ping to perform per hop.\n\n  - Type: `int`\n  - Default: `2`\n\n- `interval`\n\n  The interval in seconds between sending each packet.\n\n  - Type: `int` or `float`\n  - Default: `0.05`\n\n- `timeout`\n\n  The maximum waiting time for receiving a reply in seconds.\n\n  - Type: `int` or `float`\n  - Default: `2`\n\n- `first_hop`\n\n  The initial time to live value used in outgoing probe packets.\n\n  - Type: `int`\n  - Default: `1`\n\n- `max_hops`\n\n  The maximum time to live (max number of hops) used in outgoing probe packets.\n\n  - Type: `int`\n  - Default: `30`\n\n- `fast`\n\n  When this option is enabled and an intermediate router has been reached, skip to the next hop rather than perform additional requests. The `count` parameter then becomes the maximum number of requests in the event of no response.\n\n  - Type: `bool`\n  - Default: `False`\n\n- `id`\n\n  The identifier of ICMP requests. Used to match the responses with requests. In practice, a unique identifier should be used for every traceroute process. The library handles this identifier itself by default.\n\n  - Type: `int`\n  - Default: `None`\n\n- `source`\n\n  The IP address from which you want to send packets. By default, the interface is automatically chosen according to the specified destination.\n\n  - Type: `str`\n  - Default: `None`\n\n- `family`\n\n  The address family if a hostname or FQDN is specified. Can be set to `4` for IPv4 or `6` for IPv6 addresses. By default, this function searches for IPv4 addresses first before searching for IPv6 addresses.\n\n  - Type: `int`\n  - Default: `None`\n\n- `payload`\n\n  The payload content in bytes. A random payload is used by default.\n\n  - Type: `bytes`\n  - Default: `None`\n\n- `payload_size`\n\n  The payload size. Ignored when the `payload` parameter is set.\n\n  - Type: `int`\n  - Default: `56`\n\n- `traffic_class`\n\n  The traffic class of ICMP packets. Provides a defined level of service to packets by setting the DS Field (formerly TOS) or the Traffic Class field of IP headers. Packets are delivered with the minimum priority by default (Best-effort delivery). Intermediate routers must be able to support this feature.\n\n  *Only available on Unix systems. Ignored on Windows.*\n\n  - Type: `int`\n  - Default: `0`\n\n#### Return value\n\n- A list of `Hop` objects representing the route to the desired destination. A `Hop` has the same properties as a `Host` object but it also has a `distance`:<br>\n  `address`, `min_rtt`, `avg_rtt`, `max_rtt`, `rtts`, `packets_sent`, `packets_received`, `packet_loss`, `jitter`, `is_alive`, `distance`\n\n  The list is sorted in ascending order according to the distance, in terms of hops, that separates the remote host from the current machine. Gateways that do not respond to requests are not added to this list.\n\n#### Exceptions\n\n- `NameLookupError`\n\n  If you pass a hostname or FQDN in parameters and it does not exist or cannot be resolved.\n\n- `SocketPermissionError`\n\n  If the privileges are insufficient to create the socket.\n\n- `SocketAddressError`\n\n  If the source address cannot be assigned to the socket.\n\n- `ICMPSocketError`\n\n  If another error occurs. See the `ICMPv4Socket` or `ICMPv6Socket` class for details.\n\n#### Example\n\n```python\n>>> from icmplib import traceroute\n\n>>> hops = traceroute('1.1.1.1')\n\n>>> print('Distance/TTL    Address    Average round-trip time')\n>>> last_distance = 0\n\n>>> for hop in hops:\n...     if last_distance + 1 != hop.distance:\n...         print('Some gateways are not responding')\n...\n...     # See the Hop class for details\n...     print(f'{hop.distance}    {hop.address}    {hop.avg_rtt} ms')\n...\n...     last_distance = hop.distance\n\n# Distance/TTL    Address                 Average round-trip time\n# 1               10.0.0.1                5.196 ms\n# 2               194.149.169.49          7.552 ms\n# 3               194.149.166.54          12.21 ms\n# *               Some gateways are not responding\n# 5               212.73.205.22           22.15 ms\n# 6               1.1.1.1                 13.59 ms\n```\n\n<br>\n\n### async_ping\n\nSend ICMP Echo Request packets to a network host.\n\n*This function is non-blocking.*\n\n```python\nasync_ping(address, count=4, interval=1, timeout=2, id=None, source=None, family=None, privileged=True, **kwargs)\n```\n\n#### Parameters, return value and exceptions\n\nThe same parameters, return value and exceptions as for the `ping` function.\n\n#### Example\n\n```python\n>>> import asyncio\n>>> from icmplib import async_ping\n\n>>> async def is_alive(address):\n...     host = await async_ping(address, count=10, interval=0.2)\n...     return host.is_alive\n\n>>> asyncio.run(is_alive('1.1.1.1'))\nTrue\n```\n\n<br>\n\n### async_multiping\n\nSend ICMP Echo Request packets to several network hosts.\n\n*This function is non-blocking.*\n\n```python\nasync_multiping(addresses, count=2, interval=0.5, timeout=2, concurrent_tasks=50, source=None, family=None, privileged=True, **kwargs)\n```\n\n#### Parameters, return value and exceptions\n\nThe same parameters, return values and exceptions as for the `multiping` function.\n\n#### Example\n\n```python\n>>> import asyncio\n>>> from icmplib import async_multiping\n\n>>> async def are_alive(*addresses):\n...     hosts = await async_multiping(addresses)\n...     \n...     for host in hosts:\n...         if not host.is_alive:\n...             return False\n...\n...     return True\n\n>>> asyncio.run(are_alive('10.0.0.5', '127.0.0.1', '::1'))\nFalse\n```\n\n<br>\n\n## Documentation\n\nThis page only gives an overview of the features of icmplib.\n\nTo learn more about the built-in functions, on how to create your own and handle exceptions, you can click on the following link:\n\n- \ud83d\ude80 [Documentation](https://github.com/ValentinBELYN/icmplib/tree/main/docs)\n\n## Contributing\n\nComments and enhancements are welcome.\n\nAll development is done on [GitHub](https://github.com/ValentinBELYN/icmplib). Use [Issues](https://github.com/ValentinBELYN/icmplib/issues) to report problems and submit feature requests. Please include a minimal example that reproduces the bug.\n\n## Donate\n\nicmplib is completely free and open source. It has been fully developed on my free time. If you enjoy it, please consider donating to support the development.\n\n- \ud83c\udf89 [Donate via PayPal](https://paypal.me/ValentinBELYN)\n\n## License\n\nCopyright 2017-2023 Valentin BELYN.\n\nCode released under the GNU LGPLv3 license. See the [LICENSE](https://github.com/ValentinBELYN/icmplib/blob/main/LICENSE) for details.\n\n\n",
    "bugtrack_url": null,
    "license": "GNU Lesser General Public License v3.0",
    "summary": "Easily forge ICMP packets and make your own ping and traceroute.",
    "version": "3.0.4",
    "project_urls": {
        "Homepage": "https://github.com/ValentinBELYN/icmplib"
    },
    "split_keywords": [
        "icmp",
        "sockets",
        "ping",
        "multiping",
        "traceroute",
        "async",
        "asyncio",
        "ipv4",
        "ipv6",
        "python",
        "python3"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "38aba47a2fdcf930e986914c642242ce2823753d7b08fda485f52323132f1240",
                "md5": "5a017d66e56f110015b7656e4e84c0e0",
                "sha256": "336b75c6c23c5ce99ddec33f718fab09661f6ad698e35b6f1fc7cc0ecf809398"
            },
            "downloads": -1,
            "filename": "icmplib-3.0.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "5a017d66e56f110015b7656e4e84c0e0",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 30561,
            "upload_time": "2023-10-10T17:05:10",
            "upload_time_iso_8601": "2023-10-10T17:05:10.092516Z",
            "url": "https://files.pythonhosted.org/packages/38/ab/a47a2fdcf930e986914c642242ce2823753d7b08fda485f52323132f1240/icmplib-3.0.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6d78ca07444be85ec718d4a7617f43fdb5b4eaae40bc15a04a5c888b64f3e35f",
                "md5": "7bbbbf2daec86d619bafb23321c190cf",
                "sha256": "57868f2cdb011418c0e1d5586b16d1fabd206569fe9652654c27b6b2d6a316de"
            },
            "downloads": -1,
            "filename": "icmplib-3.0.4.tar.gz",
            "has_sig": false,
            "md5_digest": "7bbbbf2daec86d619bafb23321c190cf",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 26744,
            "upload_time": "2023-10-10T17:05:12",
            "upload_time_iso_8601": "2023-10-10T17:05:12.902702Z",
            "url": "https://files.pythonhosted.org/packages/6d/78/ca07444be85ec718d4a7617f43fdb5b4eaae40bc15a04a5c888b64f3e35f/icmplib-3.0.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-10-10 17:05:12",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "ValentinBELYN",
    "github_project": "icmplib",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "icmplib"
}
        
Elapsed time: 0.44268s