Rclone mount random slow speeds

Right, I think it's now working correctly. One single IP in hosts file at any given time during script running. One at the end, the fastest measured.

It all appears to be working just fine. There's no need to flush DNS as, I tested this, hosts file content takes precedence. As soon as I change the IP in hosts file a ping to www.googleapis.com goes to that IP.

I still suggest anyone capable of translating the script to a Windows batch file to do so. The hurdles to overcome to have it run under WSL are... tedious, let's say.

EDIT:

One thing you might wanna check out in your script: if more than one IP gives the same result, all are inserted in the hosts file but only one with correct syntax, like this:

142.251.209.42
216.58.212.170
142.250.184.42
142.250.180.170	www.googleapis.com

I don't think it creates an error in use but it might be problematic for following runs of the script, maybe? Maybe not, since hosts.backup should be an empty file and it's restored before testing... well, I thought it was worth to point this out anyway.