在vb.net中获取DNS缓存并返回域
在Visual Basic中获取DNS缓存并返回最近解析的域的最佳方法是什么?我只需要将这些域与列表进行比较在vb.net中获取DNS缓存并返回域,vb.net,Vb.net,在Visual Basic中获取DNS缓存并返回最近解析的域的最佳方法是什么?我只需要将这些域与列表进行比较 Function GetDnsCache() Dim DNSCache As New Process DNSCache.StartInfo.FileName = "ipconfig" DNSCache.StartInfo.Arguments = "/displaydns " DNSCache.StartInfo.UseShellExecute = Fals
Function GetDnsCache()
Dim DNSCache As New Process
DNSCache.StartInfo.FileName = "ipconfig"
DNSCache.StartInfo.Arguments = "/displaydns "
DNSCache.StartInfo.UseShellExecute = False
DNSCache.StartInfo.RedirectStandardOutput = True
DNSCache.
DNSCache.Start()
MsgBox(DNSCache.StandardOutput.ReadToEnd())
DNSCache.WaitForExit()
End Function
这不是最干净的方法,而且解析和加载也需要很长时间。我会这样做。它执行
ipconfig/displaydns
,并将输出附加到文件中。然后,文件被逐行读取并显示在您想要的任何位置(我使用了一个列表框)
是否要将信息显示到MsgBox中
Dim Shell = CreateObject("Wscript.Shell")
Shell.run("cmd /c ipconfig /displaydns >> C:\ipconfig.txt")
Dim reader as As New IO.StreamReader("C:\ipconfig.txt")
MsgBox(reader.ReadToEnd.ToString, MsgBoxStyle.Information)
ipconfig
不提供显示所需内容的参数。它在使用/displaydns
时显示整个DNS信息。恐怕您需要修改输出,以便删除任何不是域名的内容。
Dim Shell = CreateObject("Wscript.Shell")
Shell.run("cmd /c ipconfig /displaydns >> C:\ipconfig.txt")
Dim reader as As New IO.StreamReader("C:\ipconfig.txt")
MsgBox(reader.ReadToEnd.ToString, MsgBoxStyle.Information)