While dig and nslookup are great for looking up host names in DNS, they don’t match what a running program actually sees if there are entries in /etc/hosts.
On Linux: use getent:
getent hosts www.example.com
To get only the IPv4 address, use ahostsv4 instead of host:
getent ahostv4 www.example.com
On MacOSX, use dscacheutil:
dscacheutil -q host -a name www.example.com