many
unix or
unix-like systems handle their support for pinging
IPv6 and
IPv4 differently. some have
/bin/ping
do
IPv4 and
/bin/ping6
do
IPv6. others might have
/bin/ping4
and
/bin/ping6
. still, other might have
/bin/ping
do both. in more subtle cases, they might have
/bin/ping4
and
/bin/ping6
while also having
/bin/ping
figuring out which of those first two to run and run it (in this case, the answer for both would be
/bin/ping
.
what i would like is code that figures out
which to run. a function like
which46ping() that returns a tuple of the 2 paths would be nice
import which46ping
ping4cmd, ping6cmd = which46ping.which46ping()
such code may require knowledge about many systems. or it may do tests with some assumptions about options and/or arguments. maybe it can even include support for
windows.
ping -4 uses IPv4
ping -6 uses IPv6
ping alone should work with both
I've not used anything else. Isn't it just one ping command?
(May-10-2018, 09:02 AM)wavic Wrote: [ -> ]ping -4 uses IPv4
ping -6 uses IPv6
ping alone should work with both
I've not used anything else. Isn't it just one ping command?
not in all systems. some can figure out what to do given the IP address; some cannot. some have different executables.
Output:
lt1/forums /home/forums 1> sha384sum /bin/ping*
104ae729b7f1ee8f28b79f9ad5c82ae8f330b3ac91fd3f6a3f6f483a2114217ea32f99a6963f4dfd8ab49cb45a04a0e2 /bin/ping
803f76b3ab987e77885c3313347bf50d084d3d3ed568267066a08e978ede1a46c2d6cbf567c0162ce47c2bd04851f547 /bin/ping6
lt1/forums /home/forums 2> ls -dl /bin/ping*
-rwsr-xr-x 1 root root 44168 May 7 2014 /bin/ping
-rwsr-xr-x 1 root root 44680 May 7 2014 /bin/ping6
lt1/forums /home/forums 3>
I think all systems have ping at least. Is it possible to miss somewhere? Use just this one. Or scan /bin and /usr/bin.
You can do something like this:
def which_ping():
result = []
pings = {'/bin/ping', '/bin/ping4', '/bin/ping6',
'/usr/bin/ping', '/usr/bin/ping4', '/usr/bin/ping6'}
for dir in ('/bin'', '/usr/bin'):
entries = set(os.scandir(dir))
result.extend(list(pings & entries))
return result
Well scandinr is a generator and returns an objects but you get the idea. I am too lazy to fix it.
yes, pretty much all systems have some form of ping at least for IPv4. that makes half of my need easy. i suppose someone could build a custom system for an IPv6 only world. the question is which command for a given address family. that's what i need a program to figure out instead of guessing. maybe doing a limited finite ping to some addresses across all suspected ping commands might work. but the system might have weird commands with potentially matchable names like "pingwithtcp" or such. and some systems could have a very customized set of commands. i'm curious how others might have sorted this out.
I don't know.
As you picture it the possibilities are endless. I could have 100 servers which I want to check periodically and I could have a directory called 'scripts' in the home folder and there I could have a bash script called 'ifdown100.sh' which uses ping and I could have also just a shortcut to that file called 'ifdown100' in /usr/bin. Or I could have some Python script which uses Scapy to send ICMP echo requests which are ping requests.
The only way to know if a program is pinging something is to run it and listen to the network for those ICMP packets and to be sure that the packet is sent by your process, not another one.
yes, this certainly appears to be a complex problem. i knew it would be. so i wondered if anyone has come up with a decent solution. i guess not. that or no one around here has seen one. so i will have to come up with the best i can. if "ping6" exist then use it for IPv6, else "ping" if it exists, else None. if "ping4" exist then use it for IPv4, else "ping" if it exists, else None.
Just scan the bin directories for ping related program names. It's simple and should work because of we people have this habit to name the program after what it is doing. If it will send just a ping it has to be called ping or ping?/ping*
(May-14-2018, 04:45 AM)wavic Wrote: [ -> ]Just scan the bin directories for ping related program names. It's simple and should work because of we people have this habit to name the program after what it is doing. If it will send just a ping it has to be called ping or ping?/ping*
i thought about doing this. then i remember seeing programs that did different kinds of pings with "ping" in the name. also, i have seen "ping" in "/usr/bin". it would not surprise me if it ever shows up in "/sbin" or "/usr/sbin".
I'm always asking myself: Is this a good Idea to rely on the OS.
I learned, sometimes it's better to have the implementation in the language itself as calling outside foreign programs.
But sometimes it's very cheap just to call a program, which does the work for you.
Maybe you want to have a own implementation of ping in your utilities package:
https://github.com/samuel/python-ping/bl...er/ping.py