I want to check a ping if it was successfull or not. Now I have the problem that i had such a result with a manual ping:
Ping wird ausgeführt für 10.128.129.15 mit 32 Bytes Daten:
Antwort von 10.128.129.15: Zielhost nicht erreichbar.
Antwort von 10.128.129.15: Zielhost nicht erreichbar.
Antwort von 10.128.129.15: Zielhost nicht erreichbar.Ping-Statistik für 10.128.129.15:
Pakete: Gesendet = 3, Empfangen = 3, Verloren = 0 (0% Verlust),
# which would be an "- Success" output in my script
For every non-german person, the ping command works, but in the end it say that the DestinationHost is unreachable. I want to check if it IS reachable with the ping request, thats why I tried something like this:
def pingtest(destination,device)
print(" Pinging #{destination} #{device}: ")
#I tried to get the system output with several methods, the ping is printed
#in the consol but in the end it just returns "true"
output = system("ping -n 3 #{destination} 2>&1") #later I want >nul
puts output #prints "true"
#I tried some stuff like this: the .include? method was an
# idea from ***another Question (with ssh) and this worked
if output.content.include?("Zielhost nicht erreichbar")
puts "Success Debug"
end
#Backtick to check if the ping succeded or not..
if $? == 0
puts " - Success\n"
return true
else
puts(" - Failed\n")
return false
end
end
***another question
There i fixed my problem like this:
result = ssh.exec!"ping -c 3 #{@dest_ip}"
if result.include?("100% packet loss") || result.include?("Zeitüberschreitung") || result.include?("100% Verlust") || and so on
I didn't found a work solution for my Problem now (without a SSH connection) on SO so maybe you will have a solution for that. My goal is it to securly say if a device is reachable in the network or not. Maybe a short review about my project: I have two NAT Gateways builded with RasberyPIs - with two profinets and a network including these both profinets. I want to check now every connection in the network of this two NAT Gateways. Im a (win) Service_PC in this case running this script. More or less I need to check the command-promt while running the ping. But how?