Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Net;
- using System.Net.NetworkInformation;
- //...
- public static string GetFQDN()
- {
- string domainName = IPGlobalProperties.GetIPGlobalProperties().DomainName;
- string hostName = Dns.GetHostName();
- domainName = "." + domainName;
- if(!hostName.EndsWith(domainName)) // if hostname does not already include domain name
- {
- hostName += domainName; // add the domain name part
- }
- return hostName; // return the fully qualified name
- }
- Dns.GetHostEntry("LocalHost").HostName
- public static string GetLocalhostFqdn()
- {
- var ipProperties = IPGlobalProperties.GetIPGlobalProperties();
- return string.Format("{0}.{1}", ipProperties.HostName, ipProperties.DomainName);
- }
- Dns.GetHostEntry("LocalHost").HostName
- Dns.GetHostByName("LocalHost").HostName
- $ipProperties = [System.Net.NetworkInformation.IPGlobalProperties]::GetIPGlobalProperties()
- "{0}.{1}" -f $ipProperties.HostName, $ipProperties.DomainName
- System.Net.Dns.GetHostByName("localhost").HostName
- return System.Net.Dns.GetHostEntry(Environment.MachineName).HostName;
- public static string GetLocalhostFqdn()
- {
- var ipProperties = IPGlobalProperties.GetIPGlobalProperties();
- return string.IsNullOrWhiteSpace(ipProperties.DomainName) ? ipProperties.HostName : string.Format("{0}.{1}", ipProperties.HostName, ipProperties.DomainName);
- }
- private static string GetHostnameAndDomainName()
- {
- // if No domain name return a generic string
- string currentDomainName = IPGlobalProperties.GetIPGlobalProperties().DomainName ?? "nodomainname";
- string hostName = Dns.GetHostName();
- // check if current hostname does not contain domain name
- if (!hostName.Contains(currentDomainName))
- {
- hostName = hostName + "." + currentDomainName;
- }
- return hostName.ToLower(); // Return combined hostname and domain in lowercase
- }
- return System.Net.Dns.GetHostEntry(Environment.MachineName).HostName;
- System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName).HostName
- public static string GetLocalhostFQDN()
- {
- string domainName = string.Empty;
- try
- {
- domainName = NetworkInformation.IPGlobalProperties.GetIPGlobalProperties().DomainName;
- }
- catch
- {
- }
- string fqdn = "localhost";
- try
- {
- fqdn = System.Net.Dns.GetHostName();
- if (!string.IsNullOrEmpty(domainName))
- {
- if (!fqdn.ToLowerInvariant().EndsWith("." + domainName.ToLowerInvariant()))
- {
- fqdn += "." + domainName;
- }
- }
- }
- catch
- {
- }
- return fqdn;
- }
Add Comment
Please, Sign In to add comment