Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import ping3
- from ipaddress import IPv4Network
- from concurrent.futures import ThreadPoolExecutor, as_completed
- def ping(ip):
- try:
- available = ping3.ping(ip)
- except Exception:
- available = False
- return (ip, available)
- def getAvailableIP(network):
- result = []
- with ThreadPoolExecutor() as executor:
- futures = []
- for ip in IPv4Network(network, strict=True):
- futures.append(executor.submit(ping, str(ip)))
- for future in as_completed(futures):
- ip, available = future.result()
- if available:
- result.append(ip)
- return result
- if __name__ == '__main__':
- print(getAvailableIP('192.168.1.0/255.255.255.0'))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement