KS-Soft. Network Management Solutions
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister    ProfileProfile    Log inLog in 

PTR Check: takes a host/IP and tests for a PTR record

 
Post new topic   Reply to topic    KS-Soft Forum Index -> Library
View previous topic :: View next topic  
Author Message
terje



Joined: 25 Jul 2005
Posts: 88
Location: Sydney

PostPosted: Mon Sep 26, 2005 9:54 pm    Post subject: PTR Check: takes a host/IP and tests for a PTR record Reply with quote

We have created a script for testing whether a host/IP has a corresponding PTR record.

It takes one or two parameters.

The first parameter should be an IP address or a host name that can be resolved to an IP address.

If the IP address has a PTR record then it is compared with the original host name. If they match then the test is a success.

An optional second parameter can be used. If so then the PTR record must match this parameter for the test to be a success.

The script has been tested on a WINDOWS-2003 server running HOSTMONITOR v5.6beta.

The Hint for the script is: Params: <IP or Host> optional <Expected Result>
The start command for this script is: cmd /c %Script% %Params%

The body of the script is:-

Quote:

@echo off
REM query host name and return a PTR record status

if "%1"=="" goto NOPARAMS

setlocal

set Hostname=%1
set hostfail=***
set FILE=%temp%\~ptrcheck.%1.tmp
set FILE2=%temp%\~ptrcheck2.%1.tmp

if "%2"=="" set Expected=%hostname% else set Expected=%2

nslookup -q=a %Hostname% > %FILE2% 2>&1

FOR /F "tokens=1" %%A IN ('type %FILE2%') DO CALL :CHECKHOST %%A

FOR /F "tokens=2" %%X IN ('type %FILE2% ^| find /n "Address" ^| find "[6]Address"') DO CALL :MAINLOOP %%X
FOR /F "tokens=2" %%X IN ('type %FILE2% ^| find /n "Address" ^| find "[5]Address"') DO CALL :MAINLOOP %%X

goto ALLDONE

:MAINLOOP

nslookup -q=ptr %1 > %FILE% 2>&1

FOR /F "tokens=4" %%B IN ('type %FILE% ^| FIND /I "name ="') DO CALL :OKRECORD %%B %EXPECTED%

echo ScriptRes:Bad:%1 has no PTR
goto ALLDONE


:CHECKHOST

IF NOT %1==%hostfail% GOTO :EOF

echo ScriptRes:Unknown:host not found
goto ALLDONE

:OKRECORD

echo we are here

if "%2"=="" goto GOTEXPECTED
if "%1"=="%2" goto GOTEXPECTED

echo ScriptRes:Bad:%1
goto ALLDONE

:GOTEXPECTED

echo ScriptRes:Ok:%1
goto ALLDONE

:NOPARAMS
echo ScriptRes:Unknown:not enough parameters
goto ALLDONE

:ALLDONE

del %FILE%
del %FILE2%
exit
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    KS-Soft Forum Index -> Library All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group

KS-Soft Forum Index