kyan001 / ping3 Goto Github PK
View Code? Open in Web Editor NEWPure Python3 version of ICMP ping, shipped with command-line command.
License: MIT License
Pure Python3 version of ICMP ping, shipped with command-line command.
License: MIT License
Is it possible to get finishing hop IP on ttl expired?
And time.
This will help to simulate "traceroute" behaviour.
from ping3 import ping
res = ping('10.128.20.30')
print(res)
The code hang there for a very long time and never returns, even I set timeout and count to 2.
But when I try shell command ping
it can return results:
[root@host~]# ping -c 2 10.128.20.30
PING 10.228.94.234 (10.128.20.30) 56(84) bytes of data.
--- 10.128.20.30 ping statistics ---
2 packets transmitted, 0 received, 100% packet loss, time 40ms
Is the result Node, that is, packet loss?
In Windows 10, Python 3.8, ping version 4.0.0, using WiFi access to the network: if the laptop's WiFi disconnects, ping3.ping detects that the destination is unreachable, but then dies processing the error with an AttributeError in class DestinationUnreachable. E.g.
Traceback (most recent call last):
File "G:/My Drive/Case/PyCharm/netstats/ping_stats.py", line 47, in
result = ping3.ping(site.ipAddress, timeout=timeout, unit='ms', size=56)
File "C:\Users\dar5\AppData\Local\Programs\Python\Python38\lib\site-packages\ping3_init_.py", line 83, in wrapper
func_return = func(*args, **kwargs)
File "C:\Users\dar5\AppData\Local\Programs\Python\Python38\lib\site-packages\ping3_init_.py", line 311, in ping
delay = receive_one_ping(sock=sock, icmp_id=icmp_id, seq=seq, timeout=timeout) # in seconds
File "C:\Users\dar5\AppData\Local\Programs\Python\Python38\lib\site-packages\ping3_init_.py", line 83, in wrapper
func_return = func(*args, **kwargs)
File "C:\Users\dar5\AppData\Local\Programs\Python\Python38\lib\site-packages\ping3_init_.py", line 240, in receive_one_ping
raise errors.DestinationHostUnreachable(ip_header=ip_header, icmp_header=icmp_header)
File "C:\Users\dar5\AppData\Local\Programs\Python\Python38\lib\site-packages\ping3\errors.py", line 30, in init
super().init(self.message)
File "C:\Users\dar5\AppData\Local\Programs\Python\Python38\lib\site-packages\ping3\errors.py", line 21, in init
self.message = message if self.ip_header is None else message + " (Host='{}')".format(self.ip_header.get("src_addr"))
AttributeError: 'str' object has no attribute 'get'
Thanks a lot for the module! 👍
When i run the following code:
(python 3.10 on windows 10)
from ping3 import ping
from concurrent.futures import ThreadPoolExecutor
hosts = [
'google.com',
'yandex.ru',
'telegram.org',
'172.16.9.11',
'127.0.0.1',
]
p = ThreadPoolExecutor(max_workers=len(hosts))
for result in p.map(ping, hosts, [1] * len(hosts)):
print(result)
I get an error:
pargs = ", ".join("{}".format(arg) if isinstance(arg, str) else arg for arg in args)
TypeError: sequence item 1: expected str instance, int found
file: __init__.py line:80 in function _func_logger
for myself i solved it by replacing from
pargs = ", ".join("{}".format(arg) if isinstance(arg, str) else arg for arg in args)
to
pargs = ", ".join("'{}'".format(arg) for arg in args)
And the second assumption is that the code inside wrapper should be run only in debug mode.
Thanks for the work you've done! :)
I ran the pinging in a loop with a 1sec timeout. When timeout occurred the next (succesful) result had more than 1200 ms as the ping result, suggesting that it counted in the previous measurement in as well even though I started a completely new ping.
Does ping not support count ?
import ping3
ping3.ping(host, count=2)
Hi, I'm using the pypi source distribution and is applying some patches on top of it on Linux, more specifically it is Ubuntu 18.04. However, I just found out that the source line ending is not unix style, and I need to do the following commands to convert them in order to avoid the patch failures as the following.
Conversion command:
find . -type f | xargs dos2unix
Patch failures:
lordofire$ patch -p1 -d . -i ~/ping3_py.patch
patching file ping3/__init__.py
Hunk #1 FAILED at 229 (different line endings).
1 out of 1 hunk FAILED -- saving rejects to file ping3/__init__.py.rej
Could you please help rebuild the package with the above conversion command executed? Thanks.
I'm trying to obtain the same output like console in windows do. I corrected a library a bit and now i can receive the response TTL. But, where can i find the response payload size, to compare with sent seze? I only find the request payload, but not the response's.
Is it possible to do with build-in methods / via obtaining some values from variables in methods (than, where is this var?)
Wish u best!
Hey,
there are some things I don't understand:
verbose_ping
has a parmeter count
, but ping
doesn't?ping
return a value (seconds or an error), verbose_ping
returns nothing (even if the comment says: Returns: formatted ping results printed.
)?Can you fix this and make it a bit more consistent?
github云不能ping吗?测试每个IP结果返回都是None
I m trying to ping over 200+ host at same time, using multhreading to do it, but in evet time i get diffrent results, it seems ping3 can not identify icmp reply messages ,
This should be a proper package. Toplevel "errors" and "enums" modules make no sense whatsoever.
It would be good to have possibility to set intervals between pings.
example: interval=10 [ms]
verbose_ping('example.com', unit='ms', count=100, interval=10)
Hey, not sure how it works but could this get added to the ubuntu apt repositories?
Good day!
Your wrote ">>> ping('not-exist.com') # If timed out (no reply), returns None"
But I think, that it`s right only for IP addresses.
If we use 'not-exist domain name', then
ping('not-exist.com')
Traceback (most recent call last):
File "", line 1, in
File "C:\Python\Python36-32\lib\site-packages\ping3.py", line 121, in ping
send_one_ping(my_socket, dest_addr, my_ID)
File "C:\Python\Python36-32\lib\site-packages\ping3.py", line 86, in send_one_ping
dest_addr = socket.gethostbyname(dest_addr)
socket.gaierror: [Errno 11001] getaddrinfo failed
Thank you!
On debian 12, a failed ping returns False
, but on Fedora 38, it returns None
. This is a breaking behavior and goes against the documentation as well as all rationality; becausse of the documentation, I was testing for ping3.ping(host) is not None
but turns out that doesn't work because of this break.
Provided the Linux kernel is configured to allow non-raw ICMP for your group ID (on macOS it is available by default, you can use a SOCK_DGRAM
socket to ping without being root.
I can demonstrate this on my macOS system:
>>> import os
>>> os.getuid() # not root
501
>>> os.uname() # on MacOS
posix.uname_result(sysname='Darwin', nodename='Martijns-MacBook-Pro-2.local', release='17.7.0', version='Darwin Kernel Version 17.7.0: Thu Dec 20 21:47:19 PST 2018; root:xnu-4570.71.22~1/RELEASE_X86_64', machine='x86_64')
>>> import socket, threading, ping3
>>> ping3.DEBUG = True
>>> sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_ICMP)
>>> sock.setsockopt(socket.SOL_IP, socket.IP_TTL, 64)
>>> icmp_id = threading.current_thread().ident % 0xFFFF
>>> if True:
... ping3.send_one_ping(sock=sock, dest_addr='192.168.1.160', icmp_id=icmp_id, seq=0, size=56)
... res = ping3.receive_one_ping(sock=sock, icmp_id=icmp_id, seq=0, timeout=4)
...
[DEBUG] IP HEADER: {'version': 69, 'tos': 0, 'len': 14336, 'id': 63036, 'flags': 0, 'ttl': 64, 'protocol': 1, 'checksum': 65435, 'src_addr': 3232235936, 'dest_addr': 3232236008}
[DEBUG] ICMP HEADER: {'type': 0, 'code': 0, 'checksum': 8346, 'id': 61668, 'seq': 0}
>>> res
0.0025510787963867188
Linux enforces a suitable ICMP ID and checksum for you; there is no point in generating your own checksum (it is ignored and re-calculated) and you should not check for the ICMP ID when receiving packets as the kernel routes the packets to your socket based on their internal bookkeeping, instead.
I haven't found any proof that macOS does this however, so some platform-specific code would be needed to handle this difference. This can be as simple as ignoring the ICMP id when on Linux and not root.
Also see the Linux man 7 icmp
documentation.
Could support for this be implemented in ping3?
Hello @kyan001 ,
I would like to take the opportunity to thank you so much for this package as it saved the day many times.
Hope you are doing well. I was wondering why does the ping3.ping("example.com")
returns delay in seconds instead of returning a boolean value?
I think it would make sense if the IP address I am pinging is reachable it returns True
, otherwise it returns False
. So that when I use it to check the reachability of some hosts in my LAN, I would write something like:
import ping3
ip = "192.168.1.1"
if ping3.ping(ip):
print(f"{ip} is reachable")
else:
print(f"{ip} is unreachable")
I know that values other than 0 are evaluated to True
in if statements
and a value like 0.215697261510079666
is True
. But I think it's more of a Pythonic way.
Thank you for your consideration.
import ping3
ping3.ping("www.google.co.uk", timeout = "1", unit = "ms")
Results in:
File "pinger.py", line 2, in <module>
delay_ms = ping3.ping("www.google.co.uk", timeout = "1", unit = "ms")
File "C:\Program Files\Python37\lib\site-packages\ping3.py", line 82, in wrapper
func_return = func(*args, **kwargs)
File "C:\Program Files\Python37\lib\site-packages\ping3.py", line 292, in ping
delay = receive_one_ping(sock=sock, icmp_id=icmp_id, seq=seq, timeout=timeout) # in seconds
File "C:\Program Files\Python37\lib\site-packages\ping3.py", line 82, in wrapper
func_return = func(*args, **kwargs)
File "C:\Program Files\Python37\lib\site-packages\ping3.py", line 220, in receive_one_ping
timeout_time = time.time() + timeout # Exactly time when timeout.
TypeError: unsupported operand type(s) for +: 'float' and 'str'
Python 3.7.2, Windows, ping3 2.6.5 (just downloaded and installed it using pip as mentioned in instructions), run from an elevated command prompt
If I ping something with timeout 3s, hibernate PC and then wake up next day, ping is never end. Linux.
class DestinationHostUnreachable(DestinationUnreachable):
mybe this?
class DestinationHostUnreachable(PingError):
or
super().init(ip_header,icmp_header)
bug test in py3.9 use code
errors.DestinationHostUnreachable(ip_header=ip_header, icmp_header=icmp_header)
import multiprocessing as mp
pool=mp.Pool()
result=pool.map(verbose_ping,(arg,arg2))
print(result)
Hello again! :) I've digged in your library and found, that it's not possible to obtain TTL-expired error. Receiving timeout instead. And, as i understood from your post on stackoverflow, windows stealing packets with expired TTL from raw socket ?
Is there any updates with this problem?
Situation A) I use threading. Attempt to ping multiple servers at the same time.
(Ping is sent using threading to about 20 hosts.)
(This problem also occurs if you add a delay with time.sleep. If there are more than two pings, you will have problems.)
This problem occurs with the most recently released version.
If I use an older version, it works fine even if I send a Ping at the same time.
However, the older version has a problem that no value is returned for 5 minutes when a Timeout occurs. Therefore I can not use the old version.
Problem: Sending more than one ping at the same time or at the same time returns a timeout value.
In fact, the target host normally receives a ping.
My execution environment: I use threading. I use sleep.time.
Continue to ping about 20 hosts.
I add threading every three seconds. And it keeps running without stopping.
And that threading adds up to 30.
In the process, even though the target server is OK, Ping3 returns me a Timeout. If I ping directly from os, the response is fine.
I sincerely hope that Ping3 will be the representative package in Python 3.
I hope you can solve this problem.
Thank you.
Ping3 does not support ipv6 and that is not documented. That took me a lot of time. I dumped it for icmplib:
https://github.com/ValentinBELYN/icmplib
/usr/bin/sudo /usr/bin/python -m pip uninstall ping3
/usr/bin/sudo /usr/bin/python3 -m pip install --upgrade icmplib
I'm using the ping3 module in separate threads for every interface in the machine by the help of threading module.
Ping3 module gives the system output/prints to the screen. For that reason, I'm trying to get the system output in a variable using io module. In these case, instead of saving the output to the separate files for every thread/IP, all the outputs will be saved in a single file.
Instead of getting the output using alternative methods, is it possible to save the verbose_ping output directly to a variable? When I tried this, it returns NoneType variable.
You can see the snippets below.
threads = []
for i in range(len(IPs)):
t = Thread(target=_ping, args=(serverIP, IPs[i], duration, resultDirectoryName, ))
threads.append(t)
t.start()
for t in threads:
t.join()
It's the function that I get the results using io module.
def _ping(dest_addr, src_addr, duration, resultDirectoryName):
output = io.StringIO()
with redirect_stdout(output):
verbose_ping(dest_addr=dest_addr, count=duration, interval=1, src_addr=src_addr)
pingOutput = output.getvalue().rstrip().split("\n")
fileName = PATH_RESULT + "\\" + resultDirectoryName + "\\" + resultDirectoryName + \
"_ip" + src_addr.split(".")[-1] + ".txt"
fileName = open(fileName, "w")
fileName.writelines(output.getvalue())
fileName.close()
return pingOutput
Output file. The logs should have saved in to different files separated by IP address its send from.
ping 'google.com.tr' from '192.168.0.243' ... 62ms ping 'google.com.tr' from '192.168.0.108' ... 62ms ping 'google.com.tr' from '192.168.0.237' ... 62ms ping 'google.com.tr' from '192.168.0.243' ... 37ms ping 'google.com.tr' from '192.168.0.108' ... 84ms ping 'google.com.tr' from '192.168.0.237' ... 84ms ping 'google.com.tr' from '192.168.0.243' ... 31ms ping 'google.com.tr' from '192.168.0.108' ... 56ms ping 'google.com.tr' from '192.168.0.237' ... 56ms ping 'google.com.tr' from '192.168.0.243' ... 64ms ping 'google.com.tr' from '192.168.0.108' ... 30ms ping 'google.com.tr' from '192.168.0.237' ... 80ms ping 'google.com.tr' from '192.168.0.243' ... 29ms ping 'google.com.tr' from '192.168.0.108' ... 35ms ping 'google.com.tr' from '192.168.0.237' ... 30ms ping 'google.com.tr' from '192.168.0.243' ... 33ms ping 'google.com.tr' from '192.168.0.108' ... 28ms ping 'google.com.tr' from '192.168.0.237' ... 28ms ping 'google.com.tr' from '192.168.0.243' ... 20ms ping 'google.com.tr' from '192.168.0.108' ... 31ms ping 'google.com.tr' from '192.168.0.237' ... 22ms ping 'google.com.tr' from '192.168.0.243' ... 31ms ping 'google.com.tr' from '192.168.0.108' ... 22ms ping 'google.com.tr' from '192.168.0.237' ... 31ms ping 'google.com.tr' from '192.168.0.243' ... 29ms ping 'google.com.tr' from '192.168.0.108' ... 31ms ping 'google.com.tr' from '192.168.0.237' ... 53ms ping 'google.com.tr' from '192.168.0.243' ... 32ms
Thanks for your help.
File "D:/Code/Mercury/Mercury/qt/test.py", line 164, in
ping3.ping("www.microsoft.com")
File "D:\Code\Mercury\Mercury\qt\venv\lib\site-packages\ping3.py", line 82, in wrapper
func_return = func(*args, **kwargs)
File "D:\Code\Mercury\Mercury\qt\venv\lib\site-packages\ping3.py", line 280, in ping
sock.setsockopt(socket.SOL_IP, socket.IP_TTL, ttl)
OSError: [WinError 10022] 提供了一个无效的参数。
Using this third-party package, ping IPV6 loopback address ::1, the program returns False
from python code, not on the terminal..
ping does not timeout at set interval: I have set timeout = 1 and it still takes 4+ seconds to timeout. This happens when my router drops the DSL connection or when I shut down manually windows 10 wifi (which is the interface I'm using).
Encountered unexpected PingError Request timeout for ICMP packet. (Timeout=4s) when pinging cloudflare1.1.1.1 [DEBUG] Request timeout for ICMP packet. (Timeout=4s) [DEBUG] Function Called: ping('1.0.0.1') [DEBUG] Function Called: send_one_ping({'sock': <socket.socket fd=472, family=AddressFamily.AF_INET, type=SocketKind.SOCK_RAW, proto=1>, 'dest_addr': '1.0.0.1', 'icmp_id': 62784, 'seq': 0, 'size': 56}) [DEBUG] Destination Address: '1.0.0.1' [DEBUG] Destination Address: 1.0.0.1 [DEBUG] Sent ICMP Header: {'type': 8, 'code': 0, 'checksum': 19040, 'id': 62784, 'seq': 0} [DEBUG] Sent ICMP Payload: b'A\xd7\xdb\xdd\xe5\x86\x15\x83QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ' [DEBUG] Function Returned: send_one_ping -> None [DEBUG] Function Called: receive_one_ping({'sock': <socket.socket fd=472, family=AddressFamily.AF_INET, type=SocketKind.SOCK_RAW, proto=1, laddr=('0.0.0.0', 0)>, 'icmp_id': 62784, 'seq': 0, 'timeout': 4}) [DEBUG] Timeout time: Sat Sep 26 20:17:14 2020 [DEBUG] Timeout left: 4.00s
EDIT: Forgot to mention that, because of this bug, I've noticed occurances where the program returns values way beyond 1000 (which should be the theoretical maximum value to return, within a degree of accuracy)
Also, does not return the value in milliseconds (with the same settings as above), requiring me to convert by multiplying by 1000.
The print message inside send_one_ping (https://github.com/kyan001/ping3/blob/master/ping3.py#L84) should probably be disabled, or made configurable. For client code that uses loggers or doesnt want STDOUT this is frustrating.
Hey,
the newest release/tag is 4.0.0, but there is 4.0.4 (9fff911). I package the software on Arch Linux, so a new tag would be nice:
I haven't been able to figure out why, but sometimes after a few thousands pings (the case below 18xx), Ping3 reports no response, then 5 seconds later reports a response. When testing we had multiple terminals open all pinging at the same time, and only Ping3 comes back and says failed.
[DEBUG] Function called: ping('192.168.1.10')
[DEBUG] Function called: send_one_ping({'sock': <socket.socket fd=4, family=AddressFamily.AF_INET, type=SocketKind.SOCK_DGRAM, proto=1, laddr=('0.0.0.0', 0)>, 'dest_addr': '192.168.1.10', 'icmp_id': 30536, 'seq': 0, 'size': 56})
[DEBUG] Destination address: '192.168.1.10'
[DEBUG] Destination IP address: 192.168.1.10
[DEBUG] Sent ICMP header: {'type': 8, 'code': 0, 'checksum': 5209, 'id': 30536, 'seq': 0}
[DEBUG] Sent ICMP payload: b'A\xd8bc\x15\x89\x12\xfaQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ'
[DEBUG] Function returned: send_one_ping -> None
[DEBUG] Function called: receive_one_ping({'sock': <socket.socket fd=4, family=AddressFamily.AF_INET, type=SocketKind.SOCK_DGRAM, proto=1, laddr=('0.0.0.0', 1813)>, 'icmp_id': 30536, 'seq': 0, 'timeout': 4})
[DEBUG] Timeout time: Mon Nov 8 12:45:14 2021 (1636404314.1421816)
[DEBUG] Timeout left: 4.00s
[DEBUG] Request timeout for ICMP packet. (Timeout=4s)
[DEBUG] Function returned: ping -> None
[DEBUG] Function called: ping('192.168.1.10')
[DEBUG] Function called: send_one_ping({'sock': <socket.socket fd=4, family=AddressFamily.AF_INET, type=SocketKind.SOCK_DGRAM, proto=1, laddr=('0.0.0.0', 0)>, 'dest_addr': '192.168.1.10', 'icmp_id': 30536, 'seq': 0, 'size': 56})
[DEBUG] Destination address: '192.168.1.10'
[DEBUG] Destination IP address: 192.168.1.10
[DEBUG] Sent ICMP header: {'type': 8, 'code': 0, 'checksum': 40879, 'id': 30536, 'seq': 0}
[DEBUG] Sent ICMP payload: b'A\xd8bc4"i\nQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ'
[DEBUG] Function returned: send_one_ping -> None
[DEBUG] Function called: receive_one_ping({'sock': <socket.socket fd=4, family=AddressFamily.AF_INET, type=SocketKind.SOCK_DGRAM, proto=1, laddr=('0.0.0.0', 1814)>, 'icmp_id': 30536, 'seq': 0, 'timeout': 4})
[DEBUG] Timeout time: Mon Nov 8 12:47:16 2021 (1636404436.5383997)
[DEBUG] Timeout left: 4.00s
[DEBUG] Received time: Mon Nov 8 12:47:12 2021 (1636404432.5930107))
[DEBUG] Received ICMP header: {'type': 0, 'code': 0, 'checksum': 6114, 'id': 1814, 'seq': 0}
[DEBUG] Received ICMP payload: b'A\xd8bc4"i\nQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ'
[DEBUG] Received sent time: Mon Nov 8 12:47:12 2021 (1636404432.537661)
[DEBUG] Function returned: receive_one_ping -> 0.05534958839416504
[DEBUG] Function returned: ping -> 0.05534958839416504
[DEBUG] Function called: ping('192.168.1.10')
[DEBUG] Function called: send_one_ping({'sock': <socket.socket fd=4, family=AddressFamily.AF_INET, type=SocketKind.SOCK_DGRAM, proto=1, laddr=('0.0.0.0', 0)>, 'dest_addr': '192.168.1.10', 'icmp_id': 30536, 'seq': 0, 'size': 56})
[DEBUG] Destination address: '192.168.1.10'
[DEBUG] Destination IP address: 192.168.1.10
[DEBUG] Sent ICMP header: {'type': 8, 'code': 0, 'checksum': 47997, 'id': 30536, 'seq': 0}
[DEBUG] Sent ICMP payload: b'A\xd8bc4fL\xf8QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ'
[DEBUG] Function returned: send_one_ping -> None
[DEBUG] Function called: receive_one_ping({'sock': <socket.socket fd=4, family=AddressFamily.AF_INET, type=SocketKind.SOCK_DGRAM, proto=1, laddr=('0.0.0.0', 1815)>, 'icmp_id': 30536, 'seq': 0, 'timeout': 4})
[DEBUG] Timeout time: Mon Nov 8 12:47:17 2021 (1636404437.5993645)
[DEBUG] Timeout left: 4.00s
[DEBUG] Received time: Mon Nov 8 12:47:13 2021 (1636404433.6540964))
[DEBUG] Received ICMP header: {'type': 0, 'code': 0, 'checksum': 13231, 'id': 1815, 'seq': 0}
[DEBUG] Received ICMP payload: b'A\xd8bc4fL\xf8QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ'
[DEBUG] Received sent time: Mon Nov 8 12:47:13 2021 (1636404433.5984478)
[DEBUG] Function returned: receive_one_ping -> 0.0556485652923584
[DEBUG] Function returned: ping -> 0.0556485652923584
When I am pinging I am looking for a response, and if one I am returning True, otherwise False.
return[False if ping3.ping(host) == None else True][0]
Any thoughts on what may be causing it and how I can go about fixing it?
Сhanging ICMP packet payload size from 0 to 16:
for pack_len in range(0,16):
pack = ping(dest_ip, size=pack_len)
gives the same frame length (50 bytes) and same ICMP payload (8 bytes) in WireShark.
I have issues (strange/wrong values) with ping3 running on some machines, while on others it works great.
Testscript (compiled with pyinstaller to testping.exe):
import ping3
from ping3 import ping
ping3.DEBUG = True
ping("192.168.2.135", unit='ms')
Running Windows Ping.exe shows constant ping in 2-4ms range.
(Confirmed from both machines)
Reply from 192.168.2.135: bytes=32 time=3ms TTL=128
Reply from 192.168.2.135: bytes=32 time=2ms TTL=128
Reply from 192.168.2.135: bytes=32 time=3ms TTL=128
Reply from 192.168.2.135: bytes=32 time=3ms TTL=128
Reply from 192.168.2.135: bytes=32 time=3ms TTL=128
Reply from 192.168.2.135: bytes=32 time=3ms TTL=128
Example 1 (not working):
D:\>testping.exe
[DEBUG] Ping3 Version: 3.0.2
[DEBUG] LOGGER: <Logger ping3 (DEBUG)>
[DEBUG] Function called: ping('192.168.2.135', {'unit': 'ms'})
[DEBUG] Function called: send_one_ping({'sock': <socket.socket fd=448, family=AddressFamily.AF_INET, type=SocketKind.SOCK_RAW, proto=1>, 'dest_addr': '192.168.2.135', 'icmp_id': 17660, 'seq': 0, 'size': 56})
[DEBUG] Destination address: '192.168.2.135'
[DEBUG] Destination IP address: 192.168.2.135
[DEBUG] Sent ICMP header: {'type': 8, 'code': 0, 'checksum': 11905, 'id': 17660, 'seq': 0}
[DEBUG] Sent ICMP payload: b'A\xd8~_!\x91\x03\x1aQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ'
[DEBUG] Function returned: send_one_ping -> None
[DEBUG] Function called: receive_one_ping({'sock': <socket.socket fd=448, family=AddressFamily.AF_INET, type=SocketKind.SOCK_RAW, proto=1, laddr=('0.0.0.0', 0)>, 'icmp_id': 17660, 'seq': 0, 'timeout': 4})
[DEBUG] Timeout time: Tue Feb 1 19:31:38 2022 (1643740298.2814133)
[DEBUG] Timeout left: 4.00s
[DEBUG] Received time: Tue Feb 1 19:31:34 2022 (1643740294.2814133))
[DEBUG] Received IP header: {'version': 69, 'tos': 0, 'len': 84, 'id': 57600, 'flags': 0, 'ttl': 128, 'protocol': 1, 'checksum': 54078, 'src_addr': '192.168.2.135', 'dest_addr': '192.168.2.146'}
[DEBUG] Received ICMP header: {'type': 0, 'code': 0, 'checksum': 13953, 'id': 17660, 'seq': 0}
[DEBUG] Received ICMP payload: b'A\xd8~_!\x91\x03\x1aQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ'
[DEBUG] Received sent time: Tue Feb 1 19:31:34 2022 (1643740294.2658143)
[DEBUG] Function returned: receive_one_ping -> 0.01559901237487793
[DEBUG] Function returned: ping -> 15.59901237487793
D:\>testping.exe
[DEBUG] Ping3 Version: 3.0.2
[DEBUG] LOGGER: <Logger ping3 (DEBUG)>
[DEBUG] Function called: ping('192.168.2.135', {'unit': 'ms'})
[DEBUG] Function called: send_one_ping({'sock': <socket.socket fd=476, family=AddressFamily.AF_INET, type=SocketKind.SOCK_RAW, proto=1>, 'dest_addr': '192.168.2.135', 'icmp_id': 30537, 'seq': 0, 'size': 56})
[DEBUG] Destination address: '192.168.2.135'
[DEBUG] Destination IP address: 192.168.2.135
[DEBUG] Sent ICMP header: {'type': 8, 'code': 0, 'checksum': 64566, 'id': 30537, 'seq': 0}
[DEBUG] Sent ICMP payload: b'A\xd8~_":\x02nQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ'
[DEBUG] Function returned: send_one_ping -> None
[DEBUG] Function called: receive_one_ping({'sock': <socket.socket fd=476, family=AddressFamily.AF_INET, type=SocketKind.SOCK_RAW, proto=1, laddr=('0.0.0.0', 0)>, 'icmp_id': 30537, 'seq': 0, 'timeout': 4})
[DEBUG] Timeout time: Tue Feb 1 19:31:40 2022 (1643740300.9220686)
[DEBUG] Timeout left: 4.00s
[DEBUG] Received time: Tue Feb 1 19:31:36 2022 (1643740296.9220686))
[DEBUG] Received IP header: {'version': 69, 'tos': 0, 'len': 84, 'id': 57603, 'flags': 0, 'ttl': 128, 'protocol': 1, 'checksum': 54075, 'src_addr': '192.168.2.135', 'dest_addr': '192.168.2.146'}
[DEBUG] Received ICMP header: {'type': 0, 'code': 0, 'checksum': 1079, 'id': 30537, 'seq': 0}
[DEBUG] Received ICMP payload: b'A\xd8~_":\x02nQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ'
[DEBUG] Received sent time: Tue Feb 1 19:31:36 2022 (1643740296.9063983)
[DEBUG] Function returned: receive_one_ping -> 0.015670299530029297
[DEBUG] Function returned: ping -> 15.670299530029297
D:\>testping.exe
[DEBUG] Ping3 Version: 3.0.2
[DEBUG] LOGGER: <Logger ping3 (DEBUG)>
[DEBUG] Function called: ping('192.168.2.135', {'unit': 'ms'})
[DEBUG] Function called: send_one_ping({'sock': <socket.socket fd=448, family=AddressFamily.AF_INET, type=SocketKind.SOCK_RAW, proto=1>, 'dest_addr': '192.168.2.135', 'icmp_id': 11918, 'seq': 0, 'size': 56})
[DEBUG] Destination address: '192.168.2.135'
[DEBUG] Destination IP address: 192.168.2.135
[DEBUG] Sent ICMP header: {'type': 8, 'code': 0, 'checksum': 16780, 'id': 11918, 'seq': 0}
[DEBUG] Sent ICMP payload: b'A\xd8~_%-\x02\xe1QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ'
[DEBUG] Function returned: send_one_ping -> None
[DEBUG] Function called: receive_one_ping({'sock': <socket.socket fd=448, family=AddressFamily.AF_INET, type=SocketKind.SOCK_RAW, proto=1, laddr=('0.0.0.0', 0)>, 'icmp_id': 11918, 'seq': 0, 'timeout': 4})
[DEBUG] Timeout time: Tue Feb 1 19:31:52 2022 (1643740312.718902)
[DEBUG] Timeout left: 3.98s
[DEBUG] Received time: Tue Feb 1 19:31:48 2022 (1643740308.7345264))
[DEBUG] Received IP header: {'version': 69, 'tos': 0, 'len': 84, 'id': 57620, 'flags': 0, 'ttl': 128, 'protocol': 1, 'checksum': 54058, 'src_addr': '192.168.2.135', 'dest_addr': '192.168.2.146'}
[DEBUG] Received ICMP header: {'type': 0, 'code': 0, 'checksum': 18828, 'id': 11918, 'seq': 0}
[DEBUG] Received ICMP payload: b'A\xd8~_%-\x02\xe1QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ'
[DEBUG] Received sent time: Tue Feb 1 19:31:48 2022 (1643740308.7033007)
[DEBUG] Function returned: receive_one_ping -> 0.03122568130493164
[DEBUG] Function returned: ping -> 31.22568130493164
D:\>testping.exe
[DEBUG] Ping3 Version: 3.0.2
[DEBUG] LOGGER: <Logger ping3 (DEBUG)>
[DEBUG] Function called: ping('192.168.2.135', {'unit': 'ms'})
[DEBUG] Function called: send_one_ping({'sock': <socket.socket fd=460, family=AddressFamily.AF_INET, type=SocketKind.SOCK_RAW, proto=1>, 'dest_addr': '192.168.2.135', 'icmp_id': 30162, 'seq': 0, 'size': 56})
[DEBUG] Destination address: '192.168.2.135'
[DEBUG] Destination IP address: 192.168.2.135
[DEBUG] Sent ICMP header: {'type': 8, 'code': 0, 'checksum': 63851, 'id': 30162, 'seq': 0}
[DEBUG] Sent ICMP payload: b'A\xd8~_%\xe0\x03\nQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ'
[DEBUG] Function returned: send_one_ping -> None
[DEBUG] Function called: receive_one_ping({'sock': <socket.socket fd=460, family=AddressFamily.AF_INET, type=SocketKind.SOCK_RAW, proto=1, laddr=('0.0.0.0', 0)>, 'icmp_id': 30162, 'seq': 0, 'timeout': 4})
[DEBUG] Timeout time: Tue Feb 1 19:31:55 2022 (1643740315.5158153)
[DEBUG] Timeout left: 4.00s
[DEBUG] Received time: Tue Feb 1 19:31:51 2022 (1643740311.5158153))
[DEBUG] Received IP header: {'version': 69, 'tos': 0, 'len': 84, 'id': 57624, 'flags': 0, 'ttl': 128, 'protocol': 1, 'checksum': 54054, 'src_addr': '192.168.2.135', 'dest_addr': '192.168.2.146'}
[DEBUG] Received ICMP header: {'type': 0, 'code': 0, 'checksum': 364, 'id': 30162, 'seq': 0}
[DEBUG] Received ICMP payload: b'A\xd8~_%\xe0\x03\nQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ'
[DEBUG] Received sent time: Tue Feb 1 19:31:51 2022 (1643740311.5001855)
[DEBUG] Function returned: receive_one_ping -> 0.01562976837158203
[DEBUG] Function returned: ping -> 15.629768371582031
D:\>testping.exe
[DEBUG] Ping3 Version: 3.0.2
[DEBUG] LOGGER: <Logger ping3 (DEBUG)>
[DEBUG] Function called: ping('192.168.2.135', {'unit': 'ms'})
[DEBUG] Function called: send_one_ping({'sock': <socket.socket fd=360, family=AddressFamily.AF_INET, type=SocketKind.SOCK_RAW, proto=1>, 'dest_addr': '192.168.2.135', 'icmp_id': 8027, 'seq': 0, 'size': 56})
[DEBUG] Destination address: '192.168.2.135'
[DEBUG] Destination IP address: 192.168.2.135
[DEBUG] Sent ICMP header: {'type': 8, 'code': 0, 'checksum': 20444, 'id': 8027, 'seq': 0}
[DEBUG] Sent ICMP payload: b'A\xd8~_&\x80\x02qQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ'
[DEBUG] Function returned: send_one_ping -> None
[DEBUG] Function called: receive_one_ping({'sock': <socket.socket fd=360, family=AddressFamily.AF_INET, type=SocketKind.SOCK_RAW, proto=1, laddr=('0.0.0.0', 0)>, 'icmp_id': 8027, 'seq': 0, 'timeout': 4})
[DEBUG] Timeout time: Tue Feb 1 19:31:58 2022 (1643740318.015772)
[DEBUG] Timeout left: 4.00s
[DEBUG] Received time: Tue Feb 1 19:31:54 2022 (1643740314.015772))
[DEBUG] Received IP header: {'version': 69, 'tos': 0, 'len': 84, 'id': 57627, 'flags': 0, 'ttl': 128, 'protocol': 1, 'checksum': 54051, 'src_addr': '192.168.2.135', 'dest_addr': '192.168.2.146'}
[DEBUG] Received ICMP header: {'type': 0, 'code': 0, 'checksum': 22492, 'id': 8027, 'seq': 0}
[DEBUG] Received ICMP payload: b'A\xd8~_&\x80\x02qQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ'
[DEBUG] Received sent time: Tue Feb 1 19:31:54 2022 (1643740314.000149)
[DEBUG] Function returned: receive_one_ping -> 0.015623092651367188
[DEBUG] Function returned: ping -> 15.623092651367188
D:\>testping.exe
[DEBUG] Ping3 Version: 3.0.2
[DEBUG] LOGGER: <Logger ping3 (DEBUG)>
[DEBUG] Function called: ping('192.168.2.135', {'unit': 'ms'})
[DEBUG] Function called: send_one_ping({'sock': <socket.socket fd=436, family=AddressFamily.AF_INET, type=SocketKind.SOCK_RAW, proto=1>, 'dest_addr': '192.168.2.135', 'icmp_id': 27114, 'seq': 0, 'size': 56})
[DEBUG] Destination address: '192.168.2.135'
[DEBUG] Destination IP address: 192.168.2.135
[DEBUG] Sent ICMP header: {'type': 8, 'code': 0, 'checksum': 1110, 'id': 27114, 'seq': 0}
[DEBUG] Sent ICMP payload: b"A\xd8~_'\x15\x02\xd3QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ"
[DEBUG] Function returned: send_one_ping -> None
[DEBUG] Function called: receive_one_ping({'sock': <socket.socket fd=436, family=AddressFamily.AF_INET, type=SocketKind.SOCK_RAW, proto=1, laddr=('0.0.0.0', 0)>, 'icmp_id': 27114, 'seq': 0, 'timeout': 4})
[DEBUG] Timeout time: Tue Feb 1 19:32:00 2022 (1643740320.3282974)
[DEBUG] Timeout left: 4.00s
[DEBUG] Received time: Tue Feb 1 19:31:56 2022 (1643740316.3282974))
[DEBUG] Received IP header: {'version': 69, 'tos': 0, 'len': 84, 'id': 57630, 'flags': 0, 'ttl': 128, 'protocol': 1, 'checksum': 54048, 'src_addr': '192.168.2.135', 'dest_addr': '192.168.2.146'}
[DEBUG] Received ICMP header: {'type': 0, 'code': 0, 'checksum': 3158, 'id': 27114, 'seq': 0}
[DEBUG] Received ICMP payload: b"A\xd8~_'\x15\x02\xd3QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ"
[DEBUG] Received sent time: Tue Feb 1 19:31:56 2022 (1643740316.3282974)
[DEBUG] Function returned: receive_one_ping -> 0.0
[DEBUG] Function returned: ping -> 0.0
Example 2 (working):
>testping.exe
[DEBUG] Ping3 Version: 3.0.2
[DEBUG] LOGGER: <Logger ping3 (DEBUG)>
[DEBUG] Function called: ping('192.168.2.135', {'unit': 'ms'})
[DEBUG] Function called: send_one_ping({'sock': <socket.socket fd=452, family=AddressFamily.AF_INET, type=SocketKind.SOCK_RAW, proto=1>, 'dest_addr': '192.168.2.135', 'icmp_id': 61266, 'seq': 0, 'size': 56})
[DEBUG] Destination address: '192.168.2.135'
[DEBUG] Destination IP address: 192.168.2.135
[DEBUG] Sent ICMP header: {'type': 8, 'code': 0, 'checksum': 53596, 'id': 61266, 'seq': 0}
[DEBUG] Sent ICMP payload: b'A\xd8~_\xf3\x96\xe3\xe1QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ'
[DEBUG] Function returned: send_one_ping -> None
[DEBUG] Function called: receive_one_ping({'sock': <socket.socket fd=452, family=AddressFamily.AF_INET, type=SocketKind.SOCK_RAW, proto=1, laddr=('0.0.0.0', 0)>, 'icmp_id': 61266, 'seq': 0, 'timeout': 4})
[DEBUG] Timeout time: Tue Feb 1 19:45:38 2022 (1643741138.3580647)
[DEBUG] Timeout left: 4.00s
[DEBUG] Received time: Tue Feb 1 19:45:34 2022 (1643741134.3620949))
[DEBUG] Received IP header: {'version': 69, 'tos': 0, 'len': 84, 'id': 8054, 'flags': 0, 'ttl': 128, 'protocol': 1, 'checksum': 38095, 'src_addr': '192.168.2.135', 'dest_addr': '192.168.2.140'}
[DEBUG] Received ICMP header: {'type': 0, 'code': 0, 'checksum': 55644, 'id': 61266, 'seq': 0}
[DEBUG] Received ICMP payload: b'A\xd8~_\xf3\x96\xe3\xe1QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ'
[DEBUG] Received sent time: Tue Feb 1 19:45:34 2022 (1643741134.3576586)
[DEBUG] Function returned: receive_one_ping -> 0.0044362545013427734
[DEBUG] Function returned: ping -> 4.436254501342773
>testping.exe
[DEBUG] Ping3 Version: 3.0.2
[DEBUG] LOGGER: <Logger ping3 (DEBUG)>
[DEBUG] Function called: ping('192.168.2.135', {'unit': 'ms'})
[DEBUG] Function called: send_one_ping({'sock': <socket.socket fd=444, family=AddressFamily.AF_INET, type=SocketKind.SOCK_RAW, proto=1>, 'dest_addr': '192.168.2.135', 'icmp_id': 24465, 'seq': 0, 'size': 56})
[DEBUG] Destination address: '192.168.2.135'
[DEBUG] Destination IP address: 192.168.2.135
[DEBUG] Sent ICMP header: {'type': 8, 'code': 0, 'checksum': 1265, 'id': 24465, 'seq': 0}
[DEBUG] Sent ICMP payload: b'A\xd8~_\xf3\xf5?\xb0QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ'
[DEBUG] Function returned: send_one_ping -> None
[DEBUG] Function called: receive_one_ping({'sock': <socket.socket fd=444, family=AddressFamily.AF_INET, type=SocketKind.SOCK_RAW, proto=1, laddr=('0.0.0.0', 0)>, 'icmp_id': 24465, 'seq': 0, 'timeout': 4})
[DEBUG] Timeout time: Tue Feb 1 19:45:39 2022 (1643741139.8360164)
[DEBUG] Timeout left: 4.00s
[DEBUG] Received time: Tue Feb 1 19:45:35 2022 (1643741135.8380115))
[DEBUG] Received IP header: {'version': 69, 'tos': 0, 'len': 84, 'id': 8055, 'flags': 0, 'ttl': 128, 'protocol': 1, 'checksum': 38094, 'src_addr': '192.168.2.135', 'dest_addr': '192.168.2.140'}
[DEBUG] Received ICMP header: {'type': 0, 'code': 0, 'checksum': 3313, 'id': 24465, 'seq': 0}
[DEBUG] Received ICMP payload: b'A\xd8~_\xf3\xf5?\xb0QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ'
[DEBUG] Received sent time: Tue Feb 1 19:45:35 2022 (1643741135.8320122)
[DEBUG] Function returned: receive_one_ping -> 0.005999326705932617
[DEBUG] Function returned: ping -> 5.999326705932617
>testping.exe
[DEBUG] Ping3 Version: 3.0.2
[DEBUG] LOGGER: <Logger ping3 (DEBUG)>
[DEBUG] Function called: ping('192.168.2.135', {'unit': 'ms'})
[DEBUG] Function called: send_one_ping({'sock': <socket.socket fd=468, family=AddressFamily.AF_INET, type=SocketKind.SOCK_RAW, proto=1>, 'dest_addr': '192.168.2.135', 'icmp_id': 18621, 'seq': 0, 'size': 56})
[DEBUG] Destination address: '192.168.2.135'
[DEBUG] Destination IP address: 192.168.2.135
[DEBUG] Sent ICMP header: {'type': 8, 'code': 0, 'checksum': 37719, 'id': 18621, 'seq': 0}
[DEBUG] Sent ICMP payload: b'A\xd8~_\xf4F\xc7\xccQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ'
[DEBUG] Function returned: send_one_ping -> None
[DEBUG] Function called: receive_one_ping({'sock': <socket.socket fd=468, family=AddressFamily.AF_INET, type=SocketKind.SOCK_RAW, proto=1, laddr=('0.0.0.0', 0)>, 'icmp_id': 18621, 'seq': 0, 'timeout': 4})
[DEBUG] Timeout time: Tue Feb 1 19:45:41 2022 (1643741141.1079483)
[DEBUG] Timeout left: 4.00s
[DEBUG] Received time: Tue Feb 1 19:45:37 2022 (1643741137.1109426))
[DEBUG] Received IP header: {'version': 69, 'tos': 0, 'len': 84, 'id': 8056, 'flags': 0, 'ttl': 128, 'protocol': 1, 'checksum': 38093, 'src_addr': '192.168.2.135', 'dest_addr': '192.168.2.140'}
[DEBUG] Received ICMP header: {'type': 0, 'code': 0, 'checksum': 39767, 'id': 18621, 'seq': 0}
[DEBUG] Received ICMP payload: b'A\xd8~_\xf4F\xc7\xccQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ'
[DEBUG] Received sent time: Tue Feb 1 19:45:37 2022 (1643741137.1059446)
[DEBUG] Function returned: receive_one_ping -> 0.004997968673706055
[DEBUG] Function returned: ping -> 4.997968673706055
Using ping3 inside my full application (with e.g. threads) is even stranger:
(Again only on the one machine)
When running with ping3.DEBUG=True
:
[DEBUG] Ping3 Version: 3.0.2
[DEBUG] LOGGER: <Logger ping3 (DEBUG)>
[DEBUG] Function called: ping('192.168.2.135', {'unit': 'ms'})
[DEBUG] Function called: send_one_ping({'sock': <socket.socket fd=1460, family=AddressFamily.AF_INET, type=SocketKind.SOCK_RAW, proto=1>, 'dest_addr': '192.168.2.135', 'icmp_id': 6881, 'seq': 0, 'size': 56})
[DEBUG] Destination address: '192.168.2.135'
[DEBUG] Destination IP address: 192.168.2.135
[DEBUG] Sent ICMP header: {'type': 8, 'code': 0, 'checksum': 49313, 'id': 6881, 'seq': 0}
[DEBUG] Sent ICMP payload: b'A\xd8~^\x98\xad#\xf9QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ'
[DEBUG] Function returned: send_one_ping -> None
[DEBUG] Function called: receive_one_ping({'sock': <socket.socket fd=1460, family=AddressFamily.AF_INET, type=SocketKind.SOCK_RAW, proto=1, laddr=('0.0.0.0', 0)>, 'icmp_id': 6881, 'seq': 0, 'timeout': 4})
[DEBUG] Timeout time: Tue Feb 1 19:22:30 2022 (1643739750.716234)
[DEBUG] Timeout left: 4.00s
[DEBUG] Received time: Tue Feb 1 19:22:26 2022 (1643739746.7192607))
[DEBUG] Received IP header: {'version': 69, 'tos': 0, 'len': 84, 'id': 57060, 'flags': 0, 'ttl': 128, 'protocol': 1, 'checksum': 54618, 'src_addr': '192.168.2.135', 'dest_addr': '192.168.2.146'}
[DEBUG] Received ICMP header: {'type': 0, 'code': 0, 'checksum': 51361, 'id': 6881, 'seq': 0}
[DEBUG] Received ICMP payload: b'A\xd8~^\x98\xad#\xf9QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ'
[DEBUG] Received sent time: Tue Feb 1 19:22:26 2022 (1643739746.7053206)
[DEBUG] Function returned: receive_one_ping -> 0.013940095901489258
[DEBUG] Function returned: ping -> 13.940095901489258
[DEBUG] Function called: ping('192.168.2.135', {'unit': 'ms'})
[DEBUG] Function called: send_one_ping({'sock': <socket.socket fd=1540, family=AddressFamily.AF_INET, type=SocketKind.SOCK_RAW, proto=1>, 'dest_addr': '192.168.2.135', 'icmp_id': 6881, 'seq': 0, 'size': 56})
[DEBUG] Destination address: '192.168.2.135'
[DEBUG] Destination IP address: 192.168.2.135
[DEBUG] Sent ICMP header: {'type': 8, 'code': 0, 'checksum': 47187, 'id': 6881, 'seq': 0}
[DEBUG] Sent ICMP payload: b'A\xd8~^\x99\xa1+SQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ'
[DEBUG] Function returned: send_one_ping -> None
[DEBUG] Function called: receive_one_ping({'sock': <socket.socket fd=1540, family=AddressFamily.AF_INET, type=SocketKind.SOCK_RAW, proto=1, laddr=('0.0.0.0', 0)>, 'icmp_id': 6881, 'seq': 0, 'timeout': 4})
[DEBUG] Timeout time: Tue Feb 1 19:22:34 2022 (1643739754.5390122)
[DEBUG] Timeout left: 4.00s
[DEBUG] Received time: Tue Feb 1 19:22:30 2022 (1643739750.546621))
[DEBUG] Received IP header: {'version': 69, 'tos': 0, 'len': 84, 'id': 57065, 'flags': 0, 'ttl': 128, 'protocol': 1, 'checksum': 54613, 'src_addr': '192.168.2.135', 'dest_addr': '192.168.2.146'}
[DEBUG] Received ICMP header: {'type': 0, 'code': 0, 'checksum': 49235, 'id': 6881, 'seq': 0}
[DEBUG] Received ICMP payload: b'A\xd8~^\x99\xa1+SQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ'
[DEBUG] Received sent time: Tue Feb 1 19:22:30 2022 (1643739750.5182693)
[DEBUG] Function returned: receive_one_ping -> 0.028351783752441406
[DEBUG] Function returned: ping -> 28.351783752441406
[DEBUG] Function called: ping('192.168.2.135', {'unit': 'ms'})
[DEBUG] Function called: send_one_ping({'sock': <socket.socket fd=1552, family=AddressFamily.AF_INET, type=SocketKind.SOCK_RAW, proto=1>, 'dest_addr': '192.168.2.135', 'icmp_id': 6881, 'seq': 0, 'size': 56})
[DEBUG] Destination address: '192.168.2.135'
[DEBUG] Destination IP address: 192.168.2.135
[DEBUG] Sent ICMP header: {'type': 8, 'code': 0, 'checksum': 42675, 'id': 6881, 'seq': 0}
[DEBUG] Sent ICMP payload: b'A\xd8~^\x99\xe8<\xacQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ'
[DEBUG] Function returned: send_one_ping -> None
[DEBUG] Function called: receive_one_ping({'sock': <socket.socket fd=1552, family=AddressFamily.AF_INET, type=SocketKind.SOCK_RAW, proto=1, laddr=('0.0.0.0', 0)>, 'icmp_id': 6881, 'seq': 0, 'timeout': 4})
[DEBUG] Timeout time: Tue Feb 1 19:22:35 2022 (1643739755.651418)
[DEBUG] Timeout left: 4.00s
[DEBUG] Received time: Tue Feb 1 19:22:31 2022 (1643739751.6534476))
[DEBUG] Received IP header: {'version': 69, 'tos': 0, 'len': 84, 'id': 57067, 'flags': 0, 'ttl': 128, 'protocol': 1, 'checksum': 54611, 'src_addr': '192.168.2.135', 'dest_addr': '192.168.2.146'}
[DEBUG] Received ICMP header: {'type': 0, 'code': 0, 'checksum': 44723, 'id': 6881, 'seq': 0}
[DEBUG] Received ICMP payload: b'A\xd8~^\x99\xe8<\xacQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ'
[DEBUG] Received sent time: Tue Feb 1 19:22:31 2022 (1643739751.628703)
[DEBUG] Function returned: receive_one_ping -> 0.024744510650634766
[DEBUG] Function returned: ping -> 24.744510650634766
[DEBUG] Function called: ping('192.168.2.135', {'unit': 'ms'})
[DEBUG] Function called: send_one_ping({'sock': <socket.socket fd=1564, family=AddressFamily.AF_INET, type=SocketKind.SOCK_RAW, proto=1>, 'dest_addr': '192.168.2.135', 'icmp_id': 6881, 'seq': 0, 'size': 56})
[DEBUG] Destination address: '192.168.2.135'
[DEBUG] Destination IP address: 192.168.2.135
[DEBUG] Sent ICMP header: {'type': 8, 'code': 0, 'checksum': 11832, 'id': 6881, 'seq': 0}
[DEBUG] Sent ICMP payload: b'A\xd8~^\x9a4\xb4\xdbQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ'
[DEBUG] Function returned: send_one_ping -> None
[DEBUG] Function called: receive_one_ping({'sock': <socket.socket fd=1564, family=AddressFamily.AF_INET, type=SocketKind.SOCK_RAW, proto=1, laddr=('0.0.0.0', 0)>, 'icmp_id': 6881, 'seq': 0, 'timeout': 4})
[DEBUG] Timeout time: Tue Feb 1 19:22:36 2022 (1643739756.854092)
[DEBUG] Timeout left: 4.00s
[DEBUG] Received time: Tue Feb 1 19:22:32 2022 (1643739752.8581095))
[DEBUG] Received IP header: {'version': 69, 'tos': 0, 'len': 84, 'id': 57069, 'flags': 0, 'ttl': 128, 'protocol': 1, 'checksum': 54609, 'src_addr': '192.168.2.135', 'dest_addr': '192.168.2.146'}
[DEBUG] Received ICMP header: {'type': 0, 'code': 0, 'checksum': 13880, 'id': 6881, 'seq': 0}
[DEBUG] Received ICMP payload: b'A\xd8~^\x9a4\xb4\xdbQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ'
[DEBUG] Received sent time: Tue Feb 1 19:22:32 2022 (1643739752.8235385)
[DEBUG] Function returned: receive_one_ping -> 0.034570932388305664
[DEBUG] Function returned: ping -> 34.570932388305664
[DEBUG] Function called: ping('192.168.2.135', {'unit': 'ms'})
[DEBUG] Function called: send_one_ping({'sock': <socket.socket fd=1572, family=AddressFamily.AF_INET, type=SocketKind.SOCK_RAW, proto=1>, 'dest_addr': '192.168.2.135', 'icmp_id': 6881, 'seq': 0, 'size': 56})
[DEBUG] Destination address: '192.168.2.135'
[DEBUG] Destination IP address: 192.168.2.135
[DEBUG] Sent ICMP header: {'type': 8, 'code': 0, 'checksum': 58746, 'id': 6881, 'seq': 0}
[DEBUG] Sent ICMP payload: b'A\xd8~^\x9a\x87\xfdEQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ'
[DEBUG] Function returned: send_one_ping -> None
[DEBUG] Function called: receive_one_ping({'sock': <socket.socket fd=1572, family=AddressFamily.AF_INET, type=SocketKind.SOCK_RAW, proto=1, laddr=('0.0.0.0', 0)>, 'icmp_id': 6881, 'seq': 0, 'timeout': 4})
[DEBUG] Timeout time: Tue Feb 1 19:22:38 2022 (1643739758.1512537)
[DEBUG] Timeout left: 3.99s
[DEBUG] Received time: Tue Feb 1 19:22:34 2022 (1643739754.1659698))
[DEBUG] Received IP header: {'version': 69, 'tos': 0, 'len': 84, 'id': 57071, 'flags': 0, 'ttl': 128, 'protocol': 1, 'checksum': 54607, 'src_addr': '192.168.2.135', 'dest_addr': '192.168.2.146'}
[DEBUG] Received ICMP header: {'type': 0, 'code': 0, 'checksum': 60794, 'id': 6881, 'seq': 0}
[DEBUG] Received ICMP payload: b'A\xd8~^\x9a\x87\xfdEQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ'
[DEBUG] Received sent time: Tue Feb 1 19:22:34 2022 (1643739754.1248333)
[DEBUG] Function returned: receive_one_ping -> 0.04113650321960449
[DEBUG] Function returned: ping -> 41.13650321960449
When running the same with ping3.DEBUG=False
:
0ms, 0ms, 0ms, 0ms, 15.47ms, 0ms, 0ms, ...
(This actually was my originally issue: >90% 0ms measures...)
Both computer have Windows 10 Enterprise version 20H2.
The devices are connected to the same wireless router.
Any idea where this behaviour could come from?
Greetings,
I am trying to do multi-threading on ping3. In your code: threading.current_thread().ident
works okay and gives unique ids. However, 0xFFFF
becomes an issue. For example, 140395582191360 & 0xFFFF
is 63232 and 140395367364352 & 0xFFFF
is also 63232 😟 . For some strange reason, this issue happens quite frequently on my manjaro linux machine (1 in 5 tries). How can I overcome? Thank you in advance.
hi,I have an issue in my network, Administrator limit the ICMP packet size for security,I think the ping3 Whether Reduce the packetsize to length 64?, or make the packet size as a parameter for ping3.ping function.
Hello everybody,
with this code:
I get this result:
--> the addresses ...80, 83, 92 are working fine, but (obviously) due to result == 0 they are flagged as not working
--> the address .81 is working fine, due to result != 0 it is flagged as working
--> the addresses ...84, 89 are not working and are flagged accordingly
Any idea what to do better?
Thanks in advance
Peter
Hello, i'm triying to install in 3.11.1 version, it seems what work but VisualStudio IDE dont recognize.
Successfully installed ping3-4.0.4
ModuleNotFoundError: No module named 'ping3'
In 3.10.9 version works perfectly.
python -mping3 127.0.0.1
ping 'example.com' ... Timeout
When calling ping and specifying size it returns an error if over 1024 bytes. Looking at the ping3 code comments suggest maximum should be around 1450.
This was done on Windows 7 64 Bit SP1 Python 3.8
Traceback (most recent call last):
File "WindBackTest.py", line 203, in <module>
test_network(semIPAddress, None)
File "WindBackTest.py", line 143, in test_network
pingReturn = ping(semip, timeout=3, size=1440, unit='ms')
File "C:\Users\Controls\AppData\Local\Programs\Python\Python38\lib\site-packag
es\ping3.py", line 83, in wrapper
func_return = func(*args, **kwargs)
File "C:\Users\Controls\AppData\Local\Programs\Python\Python38\lib\site-packag
es\ping3.py", line 304, in ping
delay = receive_one_ping(sock=sock, icmp_id=icmp_id, seq=seq, timeout=timeou
t) # in seconds
File "C:\Users\Controls\AppData\Local\Programs\Python\Python38\lib\site-packag
es\ping3.py", line 83, in wrapper
func_return = func(*args, **kwargs)
File "C:\Users\Controls\AppData\Local\Programs\Python\Python38\lib\site-packag
es\ping3.py", line 220, in receive_one_ping
recv_data, addr = sock.recvfrom(1024)
OSError: [WinError 10040] A message sent on a datagram socket was larger than th
e internal message buffer or some other network limit, or the buffer used to rec
eive a datagram into was smaller than the datagram itself
Line 220 has recvfrom set to expect 1024. There might be others
Im trying to make a ping and check the status of the ping, if was sucesfull etc But i cannot find doc about library, is there anywhere?
im doing like this, but i think its a horrible way
import ping3
ping3.DEBUG = True
s = ping3.ping('192.168.1.198')
if type(s) == float:
print("Host Up")
else:
print("Host down")
According socket function documentation ( used by send_one_ping call
) IPv6 support can be simply added by using getaddrinfo.
socket.gethostbyname(hostname)
Translate a host name to IPv4 address format. The IPv4 address is returned as a string, such as '100.50.200.5'. If the host name is an IPv4 address itself it is returned unchanged. See [gethostbyname_ex()](https://docs.python.org/3/library/socket.html#socket.gethostbyname_ex) for a more complete interface. [gethostbyname()](https://docs.python.org/3/library/socket.html#socket.gethostbyname) does not support IPv6 name resolution, and [getaddrinfo()](https://docs.python.org/3/library/socket.html#socket.getaddrinfo) should be used instead for IPv4/v6 dual stack support.
Checksum calculations could be different for ipV6 packets - but potentially this might be investigated.
Exists probability that IPv6 support can be easily added to ping3 module.
On lubuntu 21.04, Python 3.9.4 ping3 2.7.0
always error: Operation not permitted
IDE: pycharm, venv
AS we cannot use Fping in windows as in Linux, but It is necessary to use it in windows, so why don't add a new feature in this python lib, it can be inputted a ip list or ip file then test ip efficiently and return an results list.
there are no another ping related libs so popular like this , if it can support ping multiple targets ,it will be more useful and popular.
thanks
Currently the ping3 only returns the delay in receive_one_ping(), but sometimes the dest ip address can be made of some usage too, so, is it possible to return the dest ip address as well?
I think a little change will be enough
init.py Line 250, current code is:
return time_recv - time_sent
change the line to:
return time_recv - time_sent, addr [0]
Hello,
I think that ping3 is buggy when used with multiprocess Process with start method "fork".
Look the code and result:
def doping2(host):
while True:
delay = ping3.ping(host)
import time; time.sleep(1)
print(host, delay)
if __name__ == "__main__":
p = argparse.ArgumentParser()
args = p.parse_args()
#mp.set_start_method('spawn')
hosts = ['a.dns.br', 'b.dns.br']
for i in hosts:
p = mp.Process(target=doping2, args=(i,))
p.start()
Result in buggy result (the hosts do not have similar delay times):
root@fat-x220-c577d2:/usr/local/bin# ping123
b.dns.br 0.051039695739746094
a.dns.br 0.05103778839111328
b.dns.br None
a.dns.br None
b.dns.br 0.054898738861083984
a.dns.br 0.054898738861083984
a.dns.br 0.05213785171508789
b.dns.br 0.05213785171508789
But if i insert:
mp.set_start_method('spawn')
it runs fine (actually a.dns.br is blocked):
root@fat-x220-c577d2:/usr/local/bin# ping123
b.dns.br 0.051796674728393555
b.dns.br 0.05194592475891113
b.dns.br 0.05153298377990723
b.dns.br 0.05203509330749512
a.dns.br None
b.dns.br 0.05774235725402832
b.dns.br 0.0719301700592041
b.dns.br 0.06660127639770508
b.dns.br 0.06898736953735352
b.dns.br 0.05692934989929199
a.dns.br None
Is it a bug or an expected result?
Thanks :-)
joel
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.