Retrieving a Domain Name

Retrieving a Domain Name

This VB function returns the DNS domain name ( 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        Else            Exit For ' Short circuit when we run out of "DC=" parts        End If    Next        ' Chop off leading '.'    strDomainName = Right$(strDomainName, Len(strDomainName) - 1)        DN2DomainName = strDomainNameEnd 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.

See also  How to Create and Deploy QR Codes Online: A Comprehensive Guide

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist