/// <summary> /// Retrieves the IPInfo for the machine on the local network with the specified MAC Address. /// </summary> /// <param name="macAddress">The MAC Address of the IPInfo to retrieve.</param> /// <returns></returns> public static IPInfo GetIPInfo(string macAddress) { var ipinfo = (from ip in IPInfo.GetIPInfo() where ip.MacAddress.ToLowerInvariant() == macAddress.ToLowerInvariant() select ip).FirstOrDefault(); return(ipinfo); }
private void getIPInfo(object data) { var ipinfoFound = false; var count = 0; // count is used to only check a certain number of times before giving up // This will keep the thread from preventing the app from exiting when the user closes the main window. while (!ipinfoFound && count < 10) { try { var pd = data as PeerDevice; var ipinfo = IPInfo.GetIPInfo(pd.Peer.MacAddress.Replace(":", "-")); if (ipinfo != null) { var hostname = ipinfo.HostName; this.Dispatcher.Invoke((Action) delegate() { this.SetIPInfoDisplay(ipinfo); }); ipinfoFound = true; } else { Thread.Sleep(1000); ipinfoFound = false; } } catch { ipinfoFound = false; } count++; } if (!ipinfoFound) { this.Dispatcher.Invoke((Action) delegate() { this.SetIPNotFound(); }); } }
private void SetIPInfoDisplay(IPInfo ipinfo) { if (ipinfo.HostName == ipinfo.IPAddress) { lblDisplayName.Content = lblDisplayName.ToolTip = ipinfo.HostName; } else { if (string.IsNullOrEmpty(ipinfo.HostName)) { lblDisplayName.Content = lblDisplayName.ToolTip = ipinfo.IPAddress; } else { lblDisplayName.Content = lblDisplayName.ToolTip = ipinfo.HostName; } } this.lblMACAddress.Content = "MAC: " + ipinfo.MacAddress; this.lblIPAddress.Content = "IP: " + ipinfo.IPAddress; this.IPAddress = ipinfo.IPAddress; this.HostName = ipinfo.HostName; }