2

Как выводить сообщение только тогда, когда все ip адреса, которые были в файле ip.txt считанные и доступные т.е. они все пингуются?

Помогите пожалуйста.

with open('ip.txt', 'r') as f:
    ips = f.readlines()
for ip in ips:
    response = os.system('ping -n 4 ' + ip)
    if response == 0:
        print(ip, 'all is up')
0

1 ответ 1

3

Попробуйте так:

with open('ip.txt', 'r') as f:
    ips = f.readlines()

response_ping = 'all is up'
_ip = ''

for ip in ips:
    response = os.system('ping -n 4 ' + ip)
    if response != 0:
        response_ping = 'Что-то пошло не так.'
        _ip = ip
        break
    
print(_ip, response_ping)
1
  • Спасибо большое! S.Nick , Вы как всегда выручаете!
    – Alex
    4 апр 2022 в 7:00

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.