SHARE
TWEET

Untitled

a guest Jan 18th, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Net;
  3. using System.Net.NetworkInformation;
  4. //...
  5.  
  6. public static string GetFQDN()
  7. {
  8.     string domainName = IPGlobalProperties.GetIPGlobalProperties().DomainName;
  9.     string hostName = Dns.GetHostName();
  10.  
  11.     domainName = "." + domainName;
  12.     if(!hostName.EndsWith(domainName))  // if hostname does not already include domain name
  13.     {
  14.         hostName += domainName;   // add the domain name part
  15.     }
  16.  
  17.     return hostName;                    // return the fully qualified name
  18. }
  19.    
  20. Dns.GetHostEntry("LocalHost").HostName
  21.    
  22. public static string GetLocalhostFqdn()
  23.     {
  24.         var ipProperties = IPGlobalProperties.GetIPGlobalProperties();
  25.         return string.Format("{0}.{1}", ipProperties.HostName, ipProperties.DomainName);
  26.     }
  27.    
  28. Dns.GetHostEntry("LocalHost").HostName
  29.    
  30. Dns.GetHostByName("LocalHost").HostName
  31.    
  32. $ipProperties = [System.Net.NetworkInformation.IPGlobalProperties]::GetIPGlobalProperties()
  33. "{0}.{1}" -f $ipProperties.HostName, $ipProperties.DomainName
  34.    
  35. System.Net.Dns.GetHostByName("localhost").HostName
  36.    
  37. return System.Net.Dns.GetHostEntry(Environment.MachineName).HostName;
  38.    
  39. public static string GetLocalhostFqdn()
  40. {
  41.     var ipProperties = IPGlobalProperties.GetIPGlobalProperties();
  42.     return string.IsNullOrWhiteSpace(ipProperties.DomainName) ? ipProperties.HostName : string.Format("{0}.{1}", ipProperties.HostName, ipProperties.DomainName);
  43. }
  44.    
  45. private static string GetHostnameAndDomainName()
  46. {
  47.        // if No domain name return a generic string          
  48.        string currentDomainName = IPGlobalProperties.GetIPGlobalProperties().DomainName ?? "nodomainname";
  49.        string hostName = Dns.GetHostName();
  50.  
  51.     // check if current hostname does not contain domain name
  52.     if (!hostName.Contains(currentDomainName))
  53.     {
  54.         hostName = hostName + "." + currentDomainName;
  55.     }
  56.     return hostName.ToLower();  // Return combined hostname and domain in lowercase
  57. }
  58.    
  59. return System.Net.Dns.GetHostEntry(Environment.MachineName).HostName;
  60.    
  61. System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName).HostName
  62.    
  63. public static string GetLocalhostFQDN()
  64.         {
  65.             string domainName = string.Empty;
  66.             try
  67.             {
  68.                 domainName = NetworkInformation.IPGlobalProperties.GetIPGlobalProperties().DomainName;
  69.             }
  70.             catch
  71.             {
  72.             }
  73.             string fqdn = "localhost";
  74.             try
  75.             {
  76.                 fqdn = System.Net.Dns.GetHostName();
  77.                 if (!string.IsNullOrEmpty(domainName))
  78.                 {
  79.                     if (!fqdn.ToLowerInvariant().EndsWith("." + domainName.ToLowerInvariant()))
  80.                     {
  81.                         fqdn += "." + domainName;
  82.                     }
  83.                 }
  84.             }
  85.             catch
  86.             {
  87.             }
  88.             return fqdn;
  89.         }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top