public static ServerInformation[] TryToGetLanList(IEnumerable<int> ports) {
var result = new List<ServerInformation>();
Parallel.ForEach(
GetBroadcastAddresses()
.SelectMany(x => ports.Select(y => new {
BroadcastIp = x,
Port = y
})),
(entry, ipLoopState) => {
var found = BroadcastPing(entry.BroadcastIp, entry.Port);
if (found == null) return;
try {
var information = TryToGetInformationDirect(found.Ip, found.Port);
if (information == null) return;
Logging.Write($"[LAN SERVERS] Found: {information.Name} ({found.Ip}:{found.Port})");
information.IsLan = true;
result.Add(information);
} catch (Exception e) {
Logging.Write("[LAN SERVERS] Error: " + e);
}
});
return result.ToArray();
}