Advertisement
Guest User

Untitled

a guest
May 30th, 2016
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. private void ResolveHostAdresses(object sender, RoutedEventArgs e)
  2. {
  3. string[] hostNames =
  4. {
  5. "www.microsoft.com",
  6. "www.apple.com", "www.google.com",
  7. "www.ibm.com", "cisco.netacad.net",
  8. "www.oracle.com", "www.nokia.com",
  9. "www.hp.com", "www.dell.com",
  10. "www.samsung.com", "www.toshiba.com",
  11. "www.siemens.com", "www.amazon.com",
  12. "www.sony.com", "www.canon.com",
  13. "www.alcatel-lucent.com", "www.acer.com",
  14. "www.motorola.com"
  15. };
  16.  
  17. var parallerQuery = hostNames.AsParallel().Select(g => new
  18. {
  19. host = g,
  20. ips = Dns.GetHostAddresses(g)
  21. });
  22.  
  23. var parallerQuery2 = from h in hostNames.AsParallel()
  24. select new
  25. {
  26. host = h,
  27. ips = Dns.GetHostAddresses(h)
  28. };
  29. //StringBuilder result = new StringBuilder();
  30. //foreach(string hostName in hostNames)
  31. //{
  32. // result.Append(hostName + " => ");
  33. // IPAddress[] ips = Dns.GetHostAddresses(hostName);
  34. // foreach (IPAddress ip in ips)
  35. // result.Append(ip.ToString());
  36.  
  37. // result.Append("\n");
  38. StringBuilder result = new StringBuilder();
  39. foreach (var adress in parallerQuery2)
  40. {
  41. result.Append(adress.host + " => ");
  42. foreach(var ip in adress.ips)
  43. result.Append(ip.ToString() + "\n");
  44. }
  45. this.hostAdressesBox.Text = result.ToString();
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement