Nov-28-2019, 02:19 AM
i have one question related to output file when ping.
if i type in 8.8.8.8 ip address it will export the ping status to the file, but if i used unreachable ip address, my temp file will only display ###result:FAIL###0.
is there any method i can let it print the same as 8.8.8.8
for example if i type in 8.8.8.8 it will print the ping result to temp.txt, but if i type in unreachable ip address it will only display fail.
is there any method i can also display below when type in unreachable ip address.
Pinging 7.7.7.7 with 32 bytes of data:
Request timed out.
i know it related to "TTL=", due to i don't want to display the ping statics
if i type in 8.8.8.8 ip address it will export the ping status to the file, but if i used unreachable ip address, my temp file will only display ###result:FAIL###0.
is there any method i can let it print the same as 8.8.8.8
for example if i type in 8.8.8.8 it will print the ping result to temp.txt, but if i type in unreachable ip address it will only display fail.
is there any method i can also display below when type in unreachable ip address.
Pinging 7.7.7.7 with 32 bytes of data:
Request timed out.
i know it related to "TTL=", due to i don't want to display the ping statics
import os import time count=0 #hostname = raw_input("enter your ip address(host): ") hostname = input("enter your ip address(host):") print ("#################start################") for i in range (2): #ping ip address response = os.system("ping -n 5 " + hostname + " | FIND " + '"TTL=" > tmp.log') #response = os.system("ping " + hostname + "> tmp.log") open('tmp.log', 'r').read() # reset modem by snmp count = 0 strCount = str(count) time.sleep( 1 ) if response == 0: count = count + 1 strCount = str(count) print ("###result:PASS###",count) print ("==============================") fd = open("tmp.log",'a+') fd.write("###result:PASS###") fd.write(strCount) fd.close() else: print ("result:FAIL") fd = open("tmp.log",'a+') fd.write("###result:FAIL###") fd.write(strCount) fd.close() break print ("#################end################") os.system("pause") #time.sleep( 5 ) #response = os.system("snmpwalk -cpublic -v 2c 192.168.41.15 1.3.6.1.2.1.69.1.4.5.0 ") #response = os.system("ping -n 5 " + hostname)