When run below code to detect if a interface with ip exist, it cost 4.5 secs on my windows machine!
import socket
import timeit
def ip_exist(host):
try:
socket.gethostbyaddr(host)
return True
except socket.herror:
return False
pass
start_time = timeit.default_timer()
retval = ip_exist("192.168.128.1")
print(retval)
print(timeit.default_timer() - start_time)
I wish the solution work for both windows and linux. please help share right way to do it!