How to get real IP address bypassing hosts file on Windows

303 views Asked by At

I added a host-ip mapping in my C:\Windows\System32\drivers\etc\hosts

192.168.1.105 www.facebook.com

I tried both getaddrinfo and DnsQuery, neither works.

The DsnQuery code is from this example. The result is:

The IP address of the host www.facebook.com is 192.168.1.105

However, the command 'nslookup' works fine:

C:\Users\abc>nslookup www.facebook.com

服务器: public1.114dns.com

Address: 114.114.114.114

非权威应答:

名称: www.facebook.com

Addresses: 200:2:2e52:ae44::

      93.46.8.89
1

There are 1 answers

0
user1633272 On

I thought DNS_QUERY_BYPASS_CACHE might do the job. But actually DNS_QUERY_NO_HOSTS_FILE should be used.