开发者

get domain name from FQDN?

I am trying to get the NetBios name from a fully qualified Domain Name...

the user inputs the FQDN and i convert to NetBios name for

eg xyz.test.com (this is just an example, the FQDN an be anything)

to its NetBios (i am not sure if it is called NetBios please feel free to correct me) name 'xyz'.

is there a way to do this..??

thanks

understanding part??

I am a bit confused with the terms...

we have clients with different FQDNs like xyz.test.com or int.hdsh.local开发者_运维百科 and so on..

i need to get the domain name out of these so i can form domain\username

so the above examples look like xyz\username and hdsh\username..

as we can see the 2nd FQDN has 2nd part as domain.

so i need help is figuring out which is the domain within a FQDN.


Are you wanting the NetBios name or just the hostname part of the FQDN?

If its just the hostname you could do

hostname=fqdn.Split('.')[0]

--EDIT

Are you looking to get the domain name for the current computer because you could just use

System.Environment.GetEnvironmentVariable("USERDOMAIN")

Of course that only works if you are running as a signed in user if you are running a non domain user (eg a service) you can use:

System.DirectoryServices.ActiveDirectory.Domain.GetComputerDomain().Name

You will need to reference the DirectoryServices.dll from the GAC. This returns the AD domain (its a FQDN) and so you would have to use the @ syntax instead of \

eg. if it came out as home.lan you would use username@home.lan


FQDN is a domain name of the computer that is findable using DNS rather than NetBIOS. If you use modernish versions of Windows I think you can use the other form: username@FQDN to form full username.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜