Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Language: VB
Expertise: Intermediate
Dec 20, 2005



Application Security Testing: An Integral Part of DevOps

Retrieving a Domain Name

This VB function returns the DNS domain name (westcoast.mycorp.com) from the passed LDAP distinguishedName (CN=Administrator,DN=Users,DC=westcoast,DC=mycorp,DC=com).

Function DN2DomainName(ByVal strDN As String)
    On Error Resume Next

    Dim strDomainName As String
    Dim strDNParts() As String
    Dim intI As Integer
    strDomainName = ""
    strDNParts = Split(strDN, ",")
    ReDim Preserve strDNParts(UBound(strDNParts))
    ' Work backwords through DN to assemble domain name
    For intI = UBound(strDNParts) To 0 Step -1
        If (InStr(UCase(strDNParts(intI)), "DC=")) Then
            strDomainName = "." & Replace(strDNParts(intI), "DC=", "") & strDomainName
            Exit For ' Short circuit when we run out of "DC=" parts
        End If
    ' Chop off leading '.'
    strDomainName = Right$(strDomainName, Len(strDomainName) - 1)
    DN2DomainName = strDomainName

End Function
Editor's Note: This code does not check to make sure the strDomainName variable has a leading period before chopping it off, nor does it check whether the final result actually fits the form of a DNS domain name, but it will work if given proper data.

Ryan Amschel
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date