asp.net getting the dns suffix ?

Necuno

Court Jester
Joined
Sep 27, 2005
Messages
58,567
this seems the be the shortest method (though not sure if the proper way) to get to the dns suffix for a machine

Code:
string hostname = Dns.GetHostName();
IPHostEntry hostEntry = Dns.GetHostEntry(hostname);
string dnsSuffix = hostEntry.HostName.Replace(hostname + ".", "");

only other methods i could find was to use ipconfig /all and "read" it from there or use the network interfaces and get it via them.

any one i missed or better manner into getting the dns suffix ?
 

Necuno

Court Jester
Joined
Sep 27, 2005
Messages
58,567
I have no idea what a DNS suffix is, but your code it returning the full domain name of the domain the machine is a member of?

There is another way to do this in C#:
Code:
using System.Net.NetworkInformation;

string myDomain= IPGlobalProperties.GetIPGlobalProperties().DomainName;

Could be different for ASP.NET?

well that does return mielies.co.za which i was for.
Code:
System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties().DomainName

this is what i meant with dns suffix
Code:
C:\Users\jdoe>ipconfig /all

Windows IP Configuration

   Host Name . . . . . . . . . . . . : ABC-PC
[COLOR="Red"][B]   Primary Dns Suffix  . . . . . . . : mielies.co.za[/B][/COLOR]
   Node Type . . . . . . . . . . . . : Hybrid
   IP Routing Enabled. . . . . . . . : No
   WINS Proxy Enabled. . . . . . . . : No
   DNS Suffix Search List. . . . . . : mielies.co.za

i think i got confused with <domain>\user and the domain the machine is part of, because my user is in the old domain still in AD and machine on our new domain. as user one returns say farm\User and machine is mielies\ABC-PC which also is the primary dns suffix of mielies.co.za. guess i should look into that a little more so i don't mix them up next time, right ? ;)
 
Last edited:

Necuno

Court Jester
Joined
Sep 27, 2005
Messages
58,567
well the machine will always be part of a domain, so guess its safe to use the GetIPGlobalProperties().DomainName. if the domain changes then the syntax will give the new domain which is in part want i want.

on the other hand the primary dns could not be present as well as the domainname could exclude the fully qualified naming which i wan looking for actually, so not "safe" to just go via GetIPGlobalProperties().DomainName.
 
Last edited:
Top