Created
May 27, 2019 01:44
-
-
Save tranductam2802/6ae638d30f8e9835f579cd98bdbf819b to your computer and use it in GitHub Desktop.
Ping all local network for finding avaiable IP address
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess | |
import ipaddress | |
from subprocess import Popen, PIPE | |
network = ipaddress.ip_network('192.168.0.0/24') | |
for idx in network.hosts(): | |
ip = str(idx) | |
toping = Popen(['ping', '-w', '300', ip], stdout=PIPE) | |
output = toping.communicate()[0] | |
hostalive = toping.returncode | |
if hostalive == 0: | |
print(ip, 'avaiable') | |
else: | |
print(ip, 'not avaiable') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment