【发布时间】:2015-06-24 19:40:43
【问题描述】:
有扫描指定地址范围的代码:
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...")
结果它的工作 - 子网中的所有主机都离线
我哪里错了?
【问题讨论】:
标签: python-3.x