This morning Douzi accidentally discovered that the company’s DNS server only had forward resolution and no corresponding PTR record. In other words, the IP address can be resolved through the domain name, but the IP address cannot find the domain name when reversed.
I wrote a very simple script in 1 hour to determine whether the existing records have corresponding reverse zone and PTR records. If not, automatically create them for me.
The idea is very simple, and the script is relatively rough. There is no fault tolerance processing or optimization, but it is just a matter of implementing the function.
$ptrzones=Get-DnsServerzone -ComputerName syddc01 | Where-Object {$_.zonename -like "*.arpa"} #获取所以的A记录 $machines=Get-DnsServerResourceRecord -ComputerName syddc01 -RRType A -ZoneName 'omnicom.com.au'| select @{n='IP';e={$_.recorddata.IPV4Address.IPAddressToString}}, hostname, timestamp, @{n='PTRZone';e={$temp=$_.recorddata.IPV4Address.IPAddressToString.split('.');$t=$temp[2]+'.'+$temp[1]+'.'+$temp[0]+‘.in-addr.arpa’;$t}} foreach($machine in $machines){ #判断是否存在PTR的reverse zone write-host $machine.hostname write-host $machine.PTRZone $flag=0 foreach($p in $ptrzones){ if($p.zonename -eq $machine.PTRZone){ #write-host " Matched PTR Zone" -BackgroundColor Cyan $flag=1 break } } #如果PTR Zone不存在,创建一个对应的 if($flag -eq 0){ write-host " PTRZone is Missing,A new PTRZone will be created" -ForegroundColor Red $temp=$machine.IP.Split('.') $range=$temp[0]+'.'+$temp[1]+'.'+$temp[2]+".0/24" #$range Add-DnsServerPrimaryZone -DynamicUpdate Secure -NetworkId $range -ReplicationScope Domain -ComputerName syddc01 } else{ #如果PTR zone存在,判断是否存在对应的PTR记录 $hname=Get-DnsServerResourceRecord -ComputerName syddc01 -RRType Ptr -ZoneName $machine.PTRZone | select @{n='name';e={$_.recorddata.ptrdomainname}} #$hname $temp="*"+$machine.hostname+"*" if($hname -like $temp){ Write-Host "Already exist" -ForegroundColor Cyan } else{ #PTR Zone存在 但是PTR记录不存在 Write-Host "Adding PTR record" -ForegroundColor Yellow Add-DnsServerResourceRecordPtr -ComputerName syddc01 -ZoneName $machine.PTRZone -Name $machine.IP.Split('.')[3] -AllowUpdateAny -TimeToLive 01:00:00 -AgeRecord -PtrDomainName $machine.hostname } } }
Execute script
Result

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft