check if ip is reachable python code example
Example 1: check if host is reachable python
HOST_UP = True if os.system("ping -c 1 " + SOMEHOST) is 0 else False
Example 2: python check if ip is up or down
import nmap, socket
ip_addr = input('Enter ip or url to check if it is up or down: ')
scanner = nmap.PortScanner()
host = socket.gethostbyname(ip_addr)
scanner.scan(host, '1', '-v')
print("IP Status: ", scanner[host].state())