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 | 5,099 views | 16/03/2014 08:38

You can use following script to verify your PTR records.

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
55
56
57
58
59
60
61
62
63
64
65
66
# Get Reverse Lookup Zones
$ReverseLookupZones = Get-DnsServerZone | Where IsReverseLookupZone -eq $True | Where IsAutoCreated -eq $False
 
foreach ($ReverseLookupZone in $ReverseLookupZones)
{
	# Clear Variables
	$Servers = $Null;
 
	# Get Zone Information
	$DNSZoneName = $ReverseLookupZone.ZoneName
 
	# Get IP Information
	$ReverseIP = $ReverseLookupZone.ZoneName.TrimEnd(".in-addr.arpa");
	$ReverseIPSuffix = $ReverseIP.Split(".")
	[array]::reverse($ReverseIPSuffix)
	$ReverseIPSuffix = $ReverseIPSuffix -join "."
 
	# Get Servers
	$Servers = Get-DnsServerResourceRecord -ZoneName $DNSZoneName | Where HostName -ne "@"
 
	foreach ($Server in $Servers)
	{		
		# Get Server IP Address
		$ServerHostName = $Server.HostName
		$ServerIPSuffix = $ServerHostName.Split(".")
		[array]::reverse($ServerIPSuffix)
		$ServerIPSuffix = $ServerIPSuffix -join "."
		$ServerIPAddress = $ReverseIPSuffix + "." + $ServerIPSuffix
 
		# Get Server DNS Hostname
		$ServerDNSName = $Server.RecordData.PtrDomainName
		$ServerDNSName = $ServerDNSName.TrimEnd(".")
 
		Write-Host Working on $ServerDNSName ..
 
		# Get Server DNS Subnet
		$ServerDNSSubnet = $ServerIPAddress.Split(".")[0] + "." + $ServerIPAddress.Split(".")[1] + "." + $ServerIPAddress.Split(".")[2] + ".0/24"
 
		# Resolve DNS Name
		$DNSName = (Resolve-DnsName $ServerDNSName)
 
		if ($DNSName)
		{
			# Clear Values
			$Control = 0;
 
			foreach ($DNSRecord in $DNSName)
			{
				# Get Reverse DNS Name
				$DNSIPAddress = $DNSRecord.IPAddress
 
				if ($DNSIPAddress -eq $ServerIPAddress)
				{
					$Control = 1;
				}
			}
 
			if ($Control -eq "0")
			{						
				$Output = $ServerIPAddress + ";" + $ServerDNSSubnet + ";" + $ServerDNSName + ";" + $DNSIPAddress
				Add-Content -Value $Output -Path PTRError.txt
				Write-Warning $Output
			}
		}
	}
}

You should run this script on your Windows Server 2012/R2 DNS server with elevated privileges.


Posted in Windows Powershell, Windows Server | No Comment | 3,163 views | 03/10/2009 22:14

Powershell üzerinden DNS kullanarak kontrol yaptırdığım scriptime, SPF desteğini ekleyerek bir üst sürüme çıkardım. Şuan sadece size SPF kayıtlarını sunuyor. Fazla vaktim olmadığı için SPF kayıtlarının kontrol ettirmedim.

# 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”)

$SPFRecord = Nslookup -type=TXT $DomainName 4.2.2.2 | Out-File C:\Results.txt
$SPFRecord = Select-String “C:\Results.txt” -Pattern ‘v=spf1’
$SPFRecord = ($SPFRecord.Get_Line()).Remove(0,1)
If ($SPFRecord -eq $Null)
{
$SPFRecord = “SPF record not exist.”
}

$Hostnames = Nslookup -type=mx $DomainName 4.2.2.2 | 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
Write-Host SPF Record: $SPFRecord

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 ” ”
}
}

Remove-Item C:\Results.txt

Gereksiz olarak eklemiş olduğum Pause function kaldırıldı. Ayrıca artık C sürücüsü içersinde bir dosya bırakmıyoruz, çıkarken siliyor :)