search
Categories
Sponsors
VirtualMetric Hyper-V Monitoring, Hyper-V Reporting
Archive
Blogroll

Badges
MCSE
Community

Cozumpark Bilisim Portali
Posted in Windows Powershell, Windows Server | No Comment | 2,691 views | 13/09/2009 15:51

I always use DNSStuff to check and verify PTR records. But DNSStuff is not a free service. Do you think you need DNSStuff when you have Powershell? This is a basic script for it. Just enter your domain name. It finds MX records then verifys PTR records. It’s simple and fast.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# PTR Record Test
# Yusuf Ozturk - MCSE+S
# http://www.yusufozturk.info
 
$local:ErrorActionPreference = "SilentlyContinue"  # Error Action Preference
 
[void][System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic')  
 
$DomainName = [Microsoft.VisualBasic.Interaction]::InputBox("Domain Name:", "", "bing.com")
 
$Hostnames = Nslookup -type=mx $DomainName 4.2.2.1 | Out-File C:\Results.txt
$Hostnames = Select-String "C:\Results.txt" -Pattern 'mail exchanger'
 
Foreach ($Hostname in $Hostnames)
{
$Hostname = ($Hostname.Get_Line() -Replace "\s","")
$Hostname = [regex]::matches($Hostname, "mailexchanger=(\w+).(\w+).(\w+).(\w+)")
$Hostname = [string]$Hostname
$Hostname = $Hostname.Remove(0,14)
 
$IPAddress = [System.Net.Dns]::GetHostAddresses("$Hostname")
 
$Status = "1"
 
Foreach ($IP in $IPAddress)
{
    $ReverseDNS = Nslookup $IP | Out-File C:\Results.txt
    $ReverseDNS = Select-String "C:\Results.txt" -Pattern 'Name'
    $ReverseDNS = ($ReverseDNS.Get_Line() -Replace "\s","").Remove(0,5)
 
    Write-Host Hostname: $Hostname
    Write-Host IP Address: $IP
 
    If ($IP -like "192.168*")
    {
    Write-Host PTR Record: localhost
    }
    Else
    {
    Write-Host PTR Record: $ReverseDNS
    }
 
    If ($ReverseDNS -eq "$Hostname")
    {
        Write-Host Result: Matched! -ForegroundColor Green
    }
    Else
    {
        Write-Host Result: Not Matched! -ForegroundColor Red
        $Status = "0"
    }
    Write-Host " "
}
}

I used 4.2.2.1 for open dns server. You need to set ExecutionPolicy as Unrestricted to execute this script.