Satbir
Satbir

Reputation: 6496

Dns.GetHostName() , From where information is retrived

I am facing problem where after changing host name my application is failing. In investigation i found that Dns.GetHostName() is still returning old host name .

I am trying to get info on source of host name for function Dns.GetHostName().

Thanks a lot

Upvotes: 6

Views: 6045

Answers (2)

Paul Farry
Paul Farry

Reputation: 4768

If you have just changed your MachineName, the new name doesn't take effect until the next time you restart your computer. I'm not 100% sure if this function works the Same way as Environment.Machinename (which is definately not updated until next restart).

Upvotes: 0

bryanmac
bryanmac

Reputation: 39296

Dns.GetHostName queries your DNS servers registered in your IP settings for your name (that's why it can return socket exception). DNS info is cached. You can do ipconfig /flushdns to clear it.

You can also get the netbios machine name from Environment.MachineName which is the static machine name from the registry. Note that netbios machine names are limited to 15 chars while DNS names are not.

Upvotes: 5

Related Questions