简体   繁体   中英

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?

PS:
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.

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

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

I solve ,my problem:

  1. Flush DNS cache

    ipconfig /flushdns

  2. Clear my hosts file.

Thank you for help!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM