Question : Modify DNS records with script or DOS command

Hi,
(We want to write our own software, not use 3rd party products)
What I am looking into is the ability to modify DNS setting via a browser (ASP script calling a DLL which is to be written in VB6).
Many web hosting companies offer this facility.

I dont know much about DNS, but I am assuming this is possible. If so any links or code snippets would be much appreciated.
Thanks

Answer : Modify DNS records with script or DOS command

Assuming you have a DNS server running and want to add your records to it -- I use the following code in VB.NET as part of my "setup hosting for a new customer" utility:

Imports System
Imports System.Management

' setup for a new domain
'  Primary zone: [domain].[tld] on main server [NS1]
'    NS [NS1]
'    NS [NS2]
'    SOA [NS1], [MAIL_ADMIN], s/n
'    MX 10, [MAILSERVER]
'    www   CNAME [WEBSERVER]
'    admin CNAME [WEBSERVER]
'    
'  Secondary zone: [domain].[tld] on secondary server [NS2]
'    
 

Module mod_MyDNS
    Public Sub DNS_Zone_Primary_Add(ByVal serverName$, ByVal zoneName$)
        ' create a new primary zone
        ' Get the object on which the method will be invoked
        Dim processClass As ManagementClass
        Dim inParams As ManagementBaseObject

        Try
            processClass = New ManagementClass("\\" & serverName & "\ROOT\MicrosoftDNS:MicrosoftDNS_Zone")

            ' Get an input parameters object for this method
            inParams = processClass.GetMethodParameters("CreateZone")

            ' Fill in input parameter values
            inParams("ZoneName") = zoneName ' eg "mycorp.com"
            inParams("ZoneType") = 1 ' Primary record
            ' Execute the method
            processClass.InvokeMethod("CreateZone", inParams, Nothing)

        Catch ex As Exception
            MsgBox("Error in DNS_Zone_Primary_Add:" & vbCrLf & ex.ToString)
        End Try
    End Sub

    Public Sub DNS_Zone_Secondary_Add(ByVal serverName$, ByVal zoneName$, ByVal primaryServerIP$)
        ' create a new secondary zone
        Dim IpAddrs$()
        Dim processClass As ManagementClass
        Dim inParams As ManagementBaseObject

        Try
            processClass = New ManagementClass("\\" & serverName & "\ROOT\MicrosoftDNS:MicrosoftDNS_Zone")

            ' Get an input parameters object for this method
            inParams = processClass.GetMethodParameters("CreateZone")

            ReDim IpAddrs(0)
            IpAddrs(0) = primaryServerIP

            ' Fill in input parameter values
            inParams("ZoneName") = zoneName ' eg. "mycorp.com"
            inParams("ZoneType") = 2 ' secondary record
            inParams("IpAddr") = IpAddrs

            ' Execute the method
            processClass.InvokeMethod("CreateZone", inParams, Nothing)

        Catch ex As Exception
            MsgBox("Error in DNS_Zone_Secondary_Add:" & vbCrLf & ex.ToString)
        End Try
    End Sub

    Public Sub DNS_RR_Add(ByVal serverName$, ByVal zoneName$, ByVal rrText$)
        ' add a generic RR (text-representation)
        ' Get the object on which the method will be invoked
        Dim processClass As ManagementClass
        Dim inParams As ManagementBaseObject

        Try
            processClass = New ManagementClass("\\" & serverName & "\ROOT\MicrosoftDNS:MicrosoftDNS_ResourceRecord")

            ' Get an input parameters object for this method
            inParams = processClass.GetMethodParameters("CreateInstanceFromTextRepresentation")

            ' Fill in input parameter values
            inParams("DnsServerName") = serverName
            inParams("ContainerName") = zoneName
            inParams("TextRepresentation") = rrText
            ' Execute the method
            Dim outParams As ManagementBaseObject = processClass.InvokeMethod("CreateInstanceFromTextRepresentation", inParams, Nothing)

        Catch ex As Exception
            MsgBox("Error in DNS_RR_Add:" & vbCrLf & ex.ToString)
        End Try
    End Sub

    Public Sub DNS_MakeSite(ByVal serverName1$, ByVal serverIP1$, _
            ByVal serverName2$, ByVal serverIP2$, ByVal zoneName$, _
            ByVal sitePrefix$, ByVal siteServer$, ByVal adminSiteServer$, _
            ByVal mailServer$, ByVal ns1Server$, ByVal ns2Server$)
        ' creates standard DNS site:
        ' Primary zone: [domain].[tld] on main server [NS1]
        '    NS [NS1]
        '    NS [NS2]
        '    SOA [NS1], [MAIL_ADMIN], s/n
        '    www   CNAME [WEBSERVER]
        '    admin CNAME [WEBSERVER]
        '    mail  CNAME [WEBSERVER]
        '    MX 10  mail.[domain].[tld]
        '    
        '  Secondary zone: [domain].[tld] on secondary server [NS2]

        ' primary
        DNS_Zone_Primary_Add(serverName1, zoneName)
        ' ns
        DNS_RR_Add(serverName1, zoneName, zoneName & " IN NS " & ns1Server)
        DNS_RR_Add(serverName1, zoneName, zoneName & " IN NS " & ns2Server)
        ' cnames
        DNS_RR_Add(serverName1, zoneName, sitePrefix & "." & zoneName & ". IN CNAME " & siteServer)
        DNS_RR_Add(serverName1, zoneName, "mail." & zoneName & ". IN CNAME " & mailServer)
        DNS_RR_Add(serverName1, zoneName, "webmail." & zoneName & ". IN CNAME " & mailServer)
        DNS_RR_Add(serverName1, zoneName, "admin." & zoneName & ". IN CNAME " & adminSiteServer)
        ' mx
        DNS_RR_Add(serverName1, zoneName, zoneName & " IN MX 10 " & "mail." & zoneName & ".")
        ' secondary zone
        DNS_Zone_Secondary_Add(serverName2, zoneName, serverIP1)
    End Sub

End Module


Works for me :)
Random Solutions  
 
programming4us programming4us