C'è un modo per svuotare la cache DNS da un'app WPF C#? L'applicazione sarebbe in esecuzione su XP, Vista o Windows 7.C'è un modo per svuotare la cache DNS da un'app WPF C#? (su XP, Vista, Win7)
risposta
Questa potrebbe essere la soluzione del povero uomo, ma è possibile utilizzare System.Diagnostics.Process
per avviare ipconfig /flushdns
.
Inoltre, sembra uno spreco di sforzi per scavare il pinvoke. –
non è un brutto ripiego - potrebbe aspettare di vedere se qualcun altro sa qualcosa di sepolto nel framework .net - penseresti che sarebbe nella classe DNS se dovunque, ma non vedo nulla lì – Greg
Finché portabilità ad altre piattaforme non è una preoccupazione, andrebbe con questo. –
È possibile utilizzare una funzione da "dnsapi.dll" di Microsoft. Questo ti permetterà di farlo in modo completamente programmatico:
using System.Runtime.InteropServices;
[DllImport("dnsapi.dll",EntryPoint="DnsFlushResolverCache")]
private static extern UInt32 DnsFlushResolverCache();
public static void FlushMyCache() //This can be named whatever name you want and is the function you will call
{
UInt32 result = DnsFlushResolverCache();
}
Ho provato questo e funziona benissimo.
Eseguo il codice e funziona, ma come faccio a sapere se il processo ha cancellato o meno la cache DNS? – mutanic
Prova questo -
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
startInfo.Arguments = "/C ipconfig /flushdns";
process.StartInfo = startInfo;
process.Start();
Sembra un po 'hacky farlo eseguendo un processo terminale. Mi aspetto che il poster originale preferisca un altro modo. – Hbcdev
Perché non avviare direttamente 'ipconfig/flushdns'? –
ho cercato su internet e non potrebbe trovare via per irrigare una sola voce DNS. Lavorando su qualcosa per fallire nel backup del data center questo è necessario per me. Ho dissimulato DnsFlushResolverCacheEntry_W e ho trovato il p/invoke sig di seguito. Io uso il metodo DnsQuery con il flag QueryNoWireFlag e NoHostFile. Se ci sono dei risultati, chiamo lo DnsFlushResolverCacheEntry_W. Questo potrebbe essere buone informazioni per qualcuno in futuro cercando di fare lo stesso
/// <summary>
/// Removes all related DNS records for the given hostname from the DNS resolver cache.
/// </summary>
/// <param name="hostName">The host name to flush from the resolver cache.</param>
/// <returns>Returns 1 if successful, zero if failed. No other error information is returned.</returns>
/// <remarks>
/// DnsFlushResolverCacheEntry_W is an undocumented method. From dissembler this method has two possible
/// return values 0 or 1. If the argument is null or the _R_ResolverFlushCacheEntry returns something
/// other than zero than the return value is zero. When _R_ResolverFlushCacheEntry returns zero the
/// return value is 1. Based off this and testing of the method it is assumed that 1 is used to indicate success.
/// After calling this method querying the DNS resolver cache returns no results.
///
/// __stdcall DnsFlushResolverCacheEntry_W(x)
/// ....
/// 6DC12729 xor esi, esi // Zero esi
/// 6DC1272B cmp [ebp+arg_0], esi // check if the hostname is null
/// 6DC1272E jz loc_6DC1D8B8 // Jump to end, return value is 0.
/// 6DC12734 mov [ebp+ms_exc.registration.TryLevel], esi
/// 6DC12737 push esi // Push 3 args for method, 2nd is hostname, others null
/// 6DC12738 push [ebp+arg_0]
/// 6DC1273B push esi
/// 6DC1273C call [email protected] // call this method
/// 6DC12741 mov [ebp+var_1C], eax // store return value in local
/// 6DC12744 mov [ebp+ms_exc.registration.TryLevel], 0FFFFFFFEh
/// 6DC1274B
/// 6DC1274B loc_6DC1274B:
/// 6DC1274B cmp [ebp+var_1C], esi
/// 6DC1274E jnz loc_6DC1D8E7 // Error? jump to block that does etw then return 0
/// 6DC12754 xor eax, eax // Success? Set eax to zero
/// 6DC12756 inc eax // result is 0, increment by 1. success return value is 1
/// 6DC12757 call __SEH_epilog4
/// 6DC1275C retn 4
///
/// 6DC1D8B8 xor eax, eax // set return value to zero
/// 6DC1D8BA jmp loc_6DC12757 // jump to end
///
/// 6DC1D8E7 mov eax, _WPP_GLOBAL_Control
/// 6DC1D8EC cmp eax, offset _WPP_GLOBAL_Control
/// 6DC1D8F1 jz short loc_6DC1D8B8
/// 6DC1D8F3 test byte ptr [eax+1Ch], 40h
/// 6DC1D8F7 jz short loc_6DC1D8B8 // This is probably testing some flag that is used to indicate if ETW is enabled
/// 6DC1D8F9 push [ebp+var_1C]
/// 6DC1D8FC push offset dword_6DC22494
/// 6DC1D901 push 0Dh
/// 6DC1D903 push dword ptr [eax+14h]
/// 6DC1D906 push dword ptr [eax+10h]
/// 6DC1D909 call [email protected] ; WPP_SF_q(x,x,x,x,x) // This method does some ETW tracing
/// 6DC1D90E jmp short loc_6DC1D8B8
/// </remarks>
[DllImport("dnsapi.dll", EntryPoint = "DnsFlushResolverCacheEntry_W", CharSet = CharSet.Unicode)]
public static extern int DnsFlushResolverCacheEntry(string hostName);
Funziona molto bene grazie – coalvilledave
- 1. Come svuotare la cache dns di php curl?
- 2. Forza chiamata ajax per svuotare la cache
- 3. Come svuotare la cache di un iFrame?
- 4. Cache DNS in linux
- 5. TextRenderer.DrawText rende Arial in modo diverso su XP vs Vista
- 6. Come svuotare la cache degli attributi nfs?
- 7. Come svuotare la cache dei pignoni?
- 8. Come svuotare la cache in Solr?
- 9. come svuotare la cache in gwt?
- 10. cache rack rack - come svuotare manualmente tutta la cache
- 11. Svuotare la cache di Symfony per un'altra applicazione
- 12. C'è un modo per NHibernate per informare la cache delle query dalle viste da invalidare?
- 13. Impostazione DNS su un VPS
- 14. Come svuotare la cache nel controller specificato in asp mvc?
- 15. Come svuotare la console in Objective-C
- 16. Come svuotare la cache di lettura del disco sotto Windows?
- 17. Come svuotare la cache del server in asp.net?
- 18. Test su IE10 su win7
- 19. Il modo migliore per svuotare lo stringstream?
- 20. inizializzare un RDD per svuotare
- 21. Risoluzione di un indirizzo IP da DNS in C#
- 22. C'è un modo per svuotare il buffer di scrittura SSL
- 23. Aggiorna DNS in coldfusion 9
- 24. SSIS ISNULL per svuotare la stringa
- 25. C'è un modo per disabilitare la cache di sistema (unix) per i file su disco?
- 26. Ricerca DNS dal server DNS personalizzato in C#
- 27. Come posso mantenere la sessione registrata e svuotare la cache tranne la sessione in memcache
- 28. Inizializza una stringa in C per svuotare la stringa
- 29. Java Web Start memorizza sempre nella cache il file JNLP su Windows XP
- 30. Fornire implementazione personalizzata per la ricerca DNS nella classe java.net.URL
http://brannickdevice.blogspot.com/2006/04/winxp-flushing-dns-programatically.html –
@Aaron: Vergogna voi non ha pubblicato come risposta. Voterò per quello. – kbrimington
@kbrimington, non mi sembrava giusto pubblicare una risposta per il primo risultato che ho trovato su google (smile): http://tinyurl.com/2bx8ngu –