[msbuild] Improved logic for obtaining local IP addresses for WiFi debug (#2835)

* [msbuild] Improved logic for obtaining local IP addresses for WiFi debug

* If we can't resolve the local host, connect to microsoft.com and use LocalEndPoint

* Use UDP instead of TCP to avoid network latency
This commit is contained in:
Jeffrey Stedfast 2017-10-05 08:00:44 -04:00 коммит произвёл Rolf Bjarne Kvinge
Родитель 0b199a7080
Коммит 8d8a071a29
1 изменённых файлов: 22 добавлений и 5 удалений

Просмотреть файл

@ -1,7 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Linq;
using System.Net.Sockets;
using System.Collections.Generic;
using System.Net.NetworkInformation;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
@ -48,12 +50,27 @@ namespace Xamarin.iOS.Tasks
hosts = DebuggerHosts.Split (new [] { ';' }, StringSplitOptions.RemoveEmptyEntries);
if (hosts == null || hosts.Length == 0) {
var properties = IPGlobalProperties.GetIPGlobalProperties ();
var hostName = properties.HostName;
try {
ips.AddRange (Dns.GetHostEntry (Dns.GetHostName ()).AddressList.Select ((v) => v.ToString ()));
var entry = Dns.GetHostEntry (hostName);
ips.AddRange (entry.AddressList.Select (v => v.ToString ()));
} catch {
using (var socket = new Socket (SocketType.Dgram, ProtocolType.Udp)) {
try {
socket.Connect ("8.8.8.8", 53);
var ipEndPoint = (IPEndPoint) socket.LocalEndPoint;
ips.Add (ipEndPoint.Address.ToString ());
} catch {
Log.MTError (7001, "Could not resolve host IPs for WiFi debugger settings.");
return false;
}
}
}
} else {
foreach (var host in hosts) {
IPAddress ip;