[enh] Improved IP detection code