Think about using dig -4 +short TXT o-o.myaddr.l.google.com @ns3.google.com instead of icanhazip.com (if there are no issues with dns/https ip mismatches). Use this also in the shell script and pass the initial first ip (and maybe the vpn check toggle and other toggles) to python - i.e. vastly simplify the ip checker to just use dig once per loop, the apis appear to be way too unreliable.