2

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.

Admiral Land
  • 2,304
  • 7
  • 43
  • 81
  • 2
    Sounds like you want the [DNS host name](http://stackoverflow.com/questions/1233217/difference-between-systeminformation-computername-environment-machinename-and). – Charles Mager Oct 10 '16 at 08:31
  • 1
    Please refer to:http://stackoverflow.com/questions/541635/how-do-i-find-the-fully-qualified-hostname-of-my-machine-in-c – Hari Palappetty Oct 10 '16 at 13:42

2 Answers2

3

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

public static string GetCurrentMachineName()
    {
        return System.Net.Dns.GetHostEntry("").HostName; //returns hostname
    }
Mostafiz
  • 7,243
  • 3
  • 28
  • 42
  • It is not work for me: for example, my hostname is hostname1. And my friend at current network has hostname named hostmane2. So, when i execute your code with `hostname2` it resolve to `hostname.company.local` and `hostname1` for me. – Admiral Land Oct 10 '16 at 13:37
0

I solve ,my problem:

  1. Flush DNS cache

    ipconfig /flushdns

  2. Clear my hosts file.

Thank you for help!

Admiral Land
  • 2,304
  • 7
  • 43
  • 81