И снова доброго времени суток! Отработал исправленный код из этой темы на локальной сети и получил в качестве результата все хосты в оффлайне.
Сам код:
import os, ipaddress
position_start=input('Start hostname: ')
position_end=input('End hostname: ')
hostname_start = ipaddress.IPv4Address(position_start)
hostname_end = ipaddress.IPv4Address(position_end)
while hostname_start <= hostname_end:
hostname_response = os.system("ping -c 1 -w 2" + str(hostname_start)+ "> /dev/null 2>&1")
if hostname_response == 0:
print (hostname_start, ' is up!\n')
else:
print (hostname_start, ' is down!\n')
hostname_start += 1
input("\nPress the enter key to exit...")
Вот например код, где я работаю напрямую ip-адресм в виде строки, испольняется отлично
import os
hostname = "8.8.8.8" #example
response = os.system("ping -c 1 -w 2 " + hostname)
#and then check the response...
if response == 0:
print (hostname, 'is up!')
else:
print (hostname, 'is down!')
Думаю, что проблема в модуле ipaddres, но не могу понять где.
P.S Решено, проблема в пропущенном пробеле в сроке
hostname_response = os.system(“ping -c 1 -w 2_____” + str(hostname_start)+ “> /dev/null 2>&1”)