File: ping.py

package info (click to toggle)
python-icmplib 2.1.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 256 kB
  • sloc: python: 1,903; makefile: 17
file content (55 lines) | stat: -rw-r--r-- 1,155 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
'''
    icmplib
    ~~~~~~~

    A powerful library for forging ICMP packets and performing ping
    and traceroute.

        https://github.com/ValentinBELYN/icmplib

    :copyright: Copyright 2017-2021 Valentin BELYN.
    :license: GNU LGPLv3, see the LICENSE for details.

    ~~~~~~~

    Example: ping
'''

from icmplib import ping


host = ping('1.1.1.1', count=10, interval=0.5, timeout=1)

# The IP address of the gateway or host that responded to the request
print(host.address)
# '1.1.1.1'

# The minimum round-trip time in milliseconds
print(host.min_rtt)
# 12.2

# The average round-trip time in milliseconds
print(host.avg_rtt)
# 13.2

# The maximum round-trip time in milliseconds
print(host.max_rtt)
# 17.6

# The number of packets transmitted to the destination host
print(host.packets_sent)
# 10

# The number of packets sent by the remote host and received by the
# current host
print(host.packets_received)
# 9

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

# Indicates whether the host is reachable
print(host.is_alive)
# True