帮我写个内网存活主机扫描脚本
时间: 2023-04-11 14:01:48 浏览: 87
好的,以下是一个简单的 Python 脚本,可以扫描指定 IP 段内的存活主机:
```python
import os
def ping(host):
response = os.system("ping -n 1 " + host)
return response == 0
def scan_network(start_ip, end_ip):
for i in range(start_ip, end_ip+1):
host = "192.168.1." + str(i)
if ping(host):
print(host + " is alive")
scan_network(1, 254)
```
这个脚本会扫描 192.168.1.1 到 192.168.1.254 这个 IP 段内的主机,如果主机存活,则会输出主机的 IP 地址。