PowerShell creates PTR reverse query for existing DNS records

Source: Internet
Author: User

This morning the bean accidentally found that the company's DNS server above only the forward parsing, and there is no corresponding PTR record. In other words, the IP address can be resolved by the domain name, but the reverse IP address is not able to find the domain name.


1 hours wrote a very simple script, to determine whether there are existing records of the corresponding reverse zone and PTR records, if not, automatically create a plus for me.


The idea is simple, the script is also relatively rough, there is no fault-tolerant processing and optimization, but the implementation of the function is good.

$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) {    # Determine if there is a reverse zone  write-host  $machine .hostname  write-host  $machine of PTR. 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 does not exist, create a corresponding   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 exist, Determine if there is a corresponding PTR record      $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 exists   but PTR records do not exist          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

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/8A/9C/wKiom1g1GgPRRmf1AACazFbSvhY540.png "style=" float: none; "title=" 9.PNG "alt=" Wkiom1g1ggprrmf1aacazfbsvhy540.png "/>


Results


650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M02/8A/9C/wKiom1g1GgSCwHkNAABsVrgiP64146.png "style=" float: none; "title=" 10.PNG "alt=" Wkiom1g1ggscwhknaabsvrgip64146.png "/>


This article is from the "Mapo Tofu" blog, please be sure to keep this source http://beanxyz.blog.51cto.com/5570417/1875747

PowerShell creates PTR reverse query for existing DNS records

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.