import os,sys,time def ping_method(): ping_success = open('ping_ok','a') ping_field = open('ping_no','a') with open('ip.txt') as ip_data: for ip in ip_data: resoult = os.system('ping -t -n 1 %s' % ip) if resoult: print('ping faild %s' % ip) ping_field.write(ip) else: print('ping success %s' % ip) ping_success.write(ip) def timesleep(hour,min,sec): return hour*3600+min*60+sec second = timesleep(0,0,10) while 1 == 1: time.sleep(second) if __name__ == '__main__': print(ping_method())