Admiral Land
Admiral Land

Reputation: 2492

How to get full host name

Enviroment.MachineName returns short name:

public static string GetCurrentMachineName()
{
    return GetMachineName(Environment.MachineName); //returns hostname
}

I have short hostname: shortName and fullname: shortName.company.local. So, when i call GetCurrentMachineName() i get only shortName instead 'shortName.company.local'. What can be wrong?

P.S.:
It is not work for me: for example, my hostname is hostname1. And my friend at current network has hostname named hostname2. So, when i execute this code:

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

with hostname2 it resolve to hostname2.company.local and hostname1 to my hostname.

Upvotes: 2

Views: 1601

Answers (2)

Admiral Land
Admiral Land

Reputation: 2492

I solve ,my problem:

  1. Flush DNS cache

    ipconfig /flushdns

  2. Clear my hosts file.

Thank you for help!

Upvotes: 0

Mostafiz
Mostafiz

Reputation: 7352

Use this Dns.GetHostEntry("").HostName to get full host name

public static string GetCurrentMachineName()
    {
        return System.Net.Dns.GetHostEntry("").HostName; //returns hostname
    }

Upvotes: 3

Related Questions