我遇到了一个名为“域污染”或“DNS缓存中毒”的问题,因此我希望通过代理将Urls解析为ip地址。我设置了系统代理,并使用下面的C#代码:
Dns.GetHostEntry("example.com").AddressList[0].ToString();
但是它仍然返回一个受污染的ip,就像ping命令返回一样。我想它没有通过代理程序。那么我应该如何通过C#中的代理解析DNS呢?
(环境: Windows 11,.Net5)
发布于 2022-08-02 11:43:12
你能试试这个吗?
DnsUtils.FlushCache("example.com");
public class DnsUtils
{
[DllImport("dnsapi.dll", EntryPoint="DnsFlushResolverCache")]
static extern UInt32 DnsFlushResolverCache();
[DllImport("dnsapi.dll", EntryPoint = "DnsFlushResolverCacheEntry_A")]
public static extern int DnsFlushResolverCacheEntry(string hostName);
public static void FlushCache()
{
DnsFlushResolverCache();
}
public static void FlushCache(string hostName)
{
DnsFlushResolverCacheEntry(hostName);
}
}
解决方案来自:BRIAN System.Net.Dns刷新缓存问题
https://stackoverflow.com/questions/73206563
复制相似问题