今天早上豆子無(wú)意中發(fā)現(xiàn)公司的DNS服務(wù)器上面只有正向的解析,而沒有對(duì)應(yīng)的PTR記錄。換句話說,可以通過域名來解析IP地址,但是倒過來IP地址是找不著域名的。
1個(gè)小時(shí)寫了個(gè)很簡(jiǎn)單的腳本,判斷已有的記錄是否存在對(duì)應(yīng)的reverse zone 和PTR記錄,如果沒有的話,自動(dòng)給我創(chuàng)建加上。
思路很簡(jiǎn)單,腳本也比較糙,沒有任何容錯(cuò)處理和優(yōu)化,不過實(shí)現(xiàn)功能就好。
$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不存在,創(chuàng)建一個(gè)對(duì)應(yīng)的 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存在,判斷是否存在對(duì)應(yīng)的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 } } }
執(zhí)行腳本
結(jié)果
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。
網(wǎng)頁(yè)名稱:PowerShell給現(xiàn)有DNS記錄創(chuàng)建PTR反向查詢-創(chuàng)新互聯(lián)
當(dāng)前地址:http://chinadenli.net/article0/ddgeoo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供App設(shè)計(jì)、電子商務(wù)、移動(dòng)網(wǎng)站建設(shè)、服務(wù)器托管、企業(yè)建站、小程序開發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容
網(wǎng)頁(yè)設(shè)計(jì)公司知識(shí)