/// <summary> /// These are the methods that get the appropriate values via different resources /// </summary> /// <returns> /// Adequate values. Either a FOUND value if found (i.e. DefaultGateway)... /// ...or EMPTY, which will infer the required value cannot be found or, in this case, the device may not be connected to a Network /// </returns> /// public string getExternalIP() { try { return(new WebClient().DownloadString("https://api.ipify.org")); } catch (Exception ex) { return(ExceptionHandling.getExceptionMessage(ex)); } }
public string getIPv4() { try { IPHostEntry IPhostEntry = Dns.GetHostEntry(Dns.GetHostName()); string IPv4 = EMPTY; foreach (IPAddress ip in IPhostEntry.AddressList) { if (ip.AddressFamily == AddressFamily.InterNetwork) { IPv4 = ip.ToString(); } } return(IPv4); } catch (Exception ex) { return(ExceptionHandling.getExceptionMessage(ex)); } }