buildenv.sh: fix ip retrieval logic