1

The following name returns machine.domain.suffix, e.g. mymachine.mydomain.local

System.Net.Dns.GetHostByName("LocalHost").HostName;

I would like to obtain only 'mydomain.local' (to target a dfs namespace).

Is there a cleaner way than using substring?

ManxJason
  • 928
  • 12
  • 33
  • 1
    It might help you - http://stackoverflow.com/questions/4161246/get-domain-name – Karthik AMR Jan 04 '17 at 13:17
  • Well, the name is hierarchical - only you know which parts have a meaning to you. – Luaan Jan 04 '17 at 13:18
  • The `HostName` is a string with a predictable format. How isn't using a substring "clean" enough for you? – rory.ap Jan 04 '17 at 13:37
  • @KarthikAMR That's exactly what I was looking for, thanks. – ManxJason Jan 04 '17 at 13:44
  • @rory.ap Well there are multiple ways to skin a cat, and I'd rather rely on a component to do it for me rather than string manipulating. IMO better code: System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties().DomainName; – ManxJason Jan 04 '17 at 13:45

1 Answers1

4

As mentioned here System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties().DomainName;

Community
  • 1
  • 1
Karthik AMR
  • 1,694
  • 21
  • 29