Part of a script I have goes through all the IP addresses in the LAN, and checks the associated FQDN.
while [[ $ws -le $total_ip ]]; do
ip="${ip_range}.${ws}"
machine=$(timeout 0.3s python3 -c "import socket; print(socket.getfqdn('$ip'))")
if[[ "$machine" = "$myMachine" ]]; then
my_ip=$ip
break
fi
done
This works right now, but takes quite a long time to complete.
I added a timeout command in front of the python command to make sure it doesn't go on for more than 0.3 seconds, but that still is quite long.
I want to know if I can thread this piece of code to speed up the process:
machine=$(timeout 0.3s python3 -c "import socket; print(socket.getfqdn('$ip'))")
if[[ "$machine" = "$myMachine" ]]; then
my_ip=$ip
break
fi
However, it needs to be native bash, because I wan't to run this on other computers without having to install any additional tools.
wsso this seems like an infinite loop.because I wan't to run this on other computers without having to install any additional tools.You are literally using python.python3 -c '<commands>' "$myMachine" "$ip_range".{0..255}is technically one line.