Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I find the fully qualified hostname of my machine in C#? [duplicate]

Ex : I want something like abc.hyd.mycompany.com. My requirement is to parse this name and initialize appropriate service.

using System.Net;  Dns.GetHostName() // doesn't return fully qualified name it just gives "abc"  
like image 556
user21246 Avatar asked Feb 12 '09 14:02

user21246


People also ask

Which command is used to get the FQDN hostname of a server?

You can check the FQDN using hostname --fqdn or the domain name using dnsdomainname. You cannot change the FQDN with hostname or dnsdomainname. Technically: The FQDN is the name getaddrinfo returns for the hostname returned by gethostname.

How do I find the fully qualified domain name from an IP address?

Type "ipconfig" and press "Enter." This displays the IP address for your Windows server. Use this IP address to view the fully qualified domain name of the server.


Video Answer


1 Answers

You may be able to get the whole DNS string like this:

System.Net.Dns.GetHostEntry("").HostName 

We don't have full fledged DNS names where I work, but it does give me a three level faux domain name instead of just the hostname.

Edit 2011/03/17: Incorporated changes suggested by mark below.

like image 102
Powerlord Avatar answered Sep 28 '22 01:09

Powerlord