Reputation: 2492
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
Reputation: 2492
I solve ,my problem:
Flush DNS cache
ipconfig /flushdns
Clear my hosts
file.
Thank you for help!
Upvotes: 0
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