Python 3.4.4 While Loop exiting and breaking right method -


dears, i'am beginner in python,now trying create script, first:filtering ip-addresses in text file(. second, checks ip availability of addresses file. code produces infinite result if example 1 of ip address not available , did not break loop message :"please re-check ip address list or device". see message after every available ip, should if of ip reachable. pls me. in advance

import re import subprocess   badlist = open("list nodes.txt", "r")  each in badlist.readlines():     badlist.seek(0)     = re.findall(r"[0-9]+(?:\.[0-9]+){3}", each)  check = false   while true :     ip in a:         ping_reply = subprocess.call(['ping', '-c', '3', '-w', '3', '-q', '-n', ip], stdout = subprocess.pipe)          if ping_reply == 0:             print ("\n %s. reachible " % ip)             check = true             continue          if ping_reply == 2:             print ("\nno response device %s." % ip)             check = false             break          else:             print ("\nping following device has failed:", ip)             check = false             break              #evaluating 'check' flag      if check == false:         print ("please re-check ip address list or device.\n")       elif check == true:         print ('\nall devices reachable. waiting command file...\n')         break 

error after executing:

python3.4 script_for_ntp.py

127.0.0.1. reachible

all devices reachable. waiting command file...

127.0.0.2. reachible

all devices reachable. waiting command file...

ping following device has failed: 8.8.8.8 please re-check ip address list or device.

ping following device has failed: 8.8.8.8 please re-check ip address list or device.

ping following device has failed: 8.8.8.8 please re-check ip address list or device.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -