I have the following block of Python code which i use to Ping multiple addresses
import subprocess as s
import tkinter as tk
from tkinter import *
IPT.title("IP Ping Test Tool")
canvas_IPT = Canvas(IPT, width=401, height=551)
canvas_IPT.pack()
Output_IP_Address_AN = Output_IP_Address[10]
IPT_Display_AN = Label(IPT, text=Output_IP_Address_AN, anchor=W)
IPT_Display_AN_Window = canvas_IPT.create_window(150, 235, anchor = 'sw', window = IPT_Display_AN)
def IPT_Test():
print("Test Initiated")
AN_Sel_State = var4.get()
if (AN_Sel_State == 1):
if(s.call(["ping", Output_IP_Address_AN])==0):
print("AvI Navi 'Ping' Sucessful")
IPT_Display_AN = Label(IPT, text=(Output_IP_Address_AN, "Ok"),fg='green', anchor=W)
IPT_Display_AN_Window = canvas_IPT.create_window(150, 235, anchor = 'sw', window = IPT_Display_AN)
else:
print("Avi Navi 'Ping' NOT Sucessful")
IPT_Display_AN = Label(IPT, text=(Output_IP_Address_AN, "Failed"),fg='red', anchor=W)
IPT_Display_AN_Window = canvas_IPT.create_window(150, 235, anchor = 'sw', window = IPT_Display_AN)
IPT_Display_AN = Label(IPT, text=Output_IP_Address_AN, anchor=W)
IPT_Display_AN_Window = canvas_IPT.create_window(150, 235, anchor = 'sw', window = IPT_Display_AN)
var4 = IntVar()
IPT_Test_AN = Checkbutton(IPT, text = "AVI/NAVI", justify=LEFT,width=15, indicatoron=0,
variable = var4, command=AN_Sel)
IPT_Test_AN_Window = canvas_IPT.create_window(20, 240, anchor = 'sw', window = IPT_Test_AN)
IPTest_Button = tk.Button(IPT, text = 'TEST', command = IPT_Test, background ="#01AEAC", width=20, height=3,)
This works as expected in instances were packet data is received (Succesful) and also works when 'Request timed out' (Not Succesful) however when 'Host Unreachable' it returns the result is successful.
Having done some research on this and i am lead to believe that "Host Unreachable" returns as ==0 even though the ping wasn't actually successful (Still dont really understand why this is ?)
If this is the case how do i exclude "Host Unreachable" from displaying successful for my application when it has the same exit status as a successful Ping ?