Microsoft DNS Integration With AppViewX

Hey Python, How Powerful You Are…….!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Recently I got one use case from one of my clients. Need to automate DNS entries in Microsoft DNS System.

In the beginning stage, it was very difficult for me to integrate with such kinds of systems. The risk factor is normally when we integrate with external DNS platforms ( DNS devices like Infoblox, Bluecat, etc.), it should have a proper communication channel like Rest APIs, and commands, or we can connect the device directly through SSH and perform some operations on the device itself.

But in this case, the destination environment is Windows DNS and it's new to me also there is no API and commands to perform the DNS operations. I’m a bit confused and tense at the beginning stage.

After long research, I found one python package from https://pypy.org/

Package Name :- pypsrp (https://pypi.org/project/pypsrp/)

pypsrp is a Python client for the PowerShell Remoting Protocol (PSRP) and Windows Remote Management (WinRM) service. It allows you to execute commands on a remote Windows host from any machine that can run Python

Simply, this package is used to connect the windows system through WinRM service and we can execute the PowerShell commands within the window system,

Also, this package supports various authentication modes like Kerberos authentication and CredSSP authentication normally which are used in windows platforms.

I think I need to give a small idea about What Is Powershell?

Powershell:-

PowerShell is a task-based command-line shell and scripting language built on. NET. PowerShell helps system administrators and power users rapidly automate tasks that manage operating systems (Linux, macOS, and Windows) and processes. PowerShell commands let you manage computers from the command line

So finally I got one breakthrough. Now I can connect to the windows system and execute PowerShell commands by using pypsrp.

But my final goal needs to automate the Microsoft DNS. Microsoft itself provides various PowerShell cmdlet modules to automate DNS systems.

https://docs.microsoft.com/en-us/powershell/module/dnsserver/?view=win10-ps

This document support windows10 and above. Also contain different PowerShell command and scripts to automate the DNS operation, For this use case I have done some of the operations, but you can use this documentation for the complete DNS automation by using PowerShell and python.

Below are the operations which are done through this mechanism on MS DNS for my use case.

1. List all the zones available in the Microsoft DNS system

2. Create a Host Record

3. Create PTR Record

4. Create CNAME Record

5. Check whether the Host Record is available or not?

6. Check whether the CNAME is available or not?

7. Delete Host Record

8. Delete PTR Record

9. Delete CNAME Record

Please find the sample python code snippet for getting all the available forward zones from MS DNS.

from pypsrp.client import Clientms_connection = Client(SERVER URL, username=USERNAME, password=PASSWORD,ssl=False)powershell_script_for_getting_zones = """$myarray = @()        $Zones = @(Get-DnsServerZone -ComputerName {name})        ForEach ($Zone in $Zones) {{        $myarray = $myarray +$Zone.ZoneName        }}        Write-Output $myarray        """.format(name=MS_DNS_DEVICE)output, streams, had_errors = connection.execute_ps(powershell_script_for_getting_zones)

Hope this article helps you when such kind of integrations are needed.!!!!!!!!!!!!!!!!

--

--