Ich hab’ gerade ‘nen kleines Tool für Windows zusammen gehackt und festgestellt, dass die .NET DNS-APIs keine Möglichkeit haben einen Timout zu übergeben und immer 5sek. warten.
Hier ‘nen kleiner haufen Code, welcher das Problem umgehen sollte:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | private delegate System.Net.IPHostEntry GetHostEntryHandler(string ip); public string lookup(string host, int timeout) { try { GetHostEntryHandler callback = new GetHostEntryHandler(Dns.GetHostEntry); IAsyncResult result = callback.BeginInvoke(host, null, null); if (result.AsyncWaitHandle.WaitOne(timeout, false)) { foreach (System.Net.IPAddress ip in callback.EndInvoke(result).AddressList) { return ip.ToString(); } return null; } else { return null; } } catch (Exception) { return null; } } public string reverseLookup(string host, int timeout) { try { GetHostEntryHandler callback = new GetHostEntryHandler(Dns.GetHostEntry); IAsyncResult result = callback.BeginInvoke(host, null, null); if (result.AsyncWaitHandle.WaitOne(timeout, false)) { return callback.EndInvoke(result).HostName; } else { return host; } } catch (Exception) { return null; } } |

zycho
27. April 2011 at 10:53
twitter lieber mal. lg, zycho