def scan(network):
myip_subnet = subprocess.getoutput("/sbin/ip -o -f inet addr show | awk '/scope global/ {print $4}'")
nm.scan(hosts=myip_subnet, arguments='nmap -sn')
iplist = []
# add localhost
iplist.append({'ip_addr': '127.0.0.1', 'host': 'localhost'})
for host in nm.all_hosts():
try:
ip_a = (nm[host]['addresses']['ipv4'])
except KeyError:
ip_a = "[Unknown IP]"
try:
host_name = nm[host].hostname()
except KeyError:
host_name = "[Unknown hostname]"
iplist.append({'ip_addr': ip_a, 'host': host_name})
return iplist
评论列表
文章目录