home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 18 REXX
/
18-REXX.zip
/
dhcpxref.zip
/
DHCPXREF.CMD
Wrap
OS/2 REXX Batch file
|
2002-02-07
|
9KB
|
304 lines
/**********************************************************************
* DHCPXREF
* by Peter Degotardi
* Revised MAY 6, 1998
*
* DHCPXREF
* Return values: 0=successful, 1=Problem with NSSIG
* 2=Problem with DADMIN
*
* Use NSSIG and DADMIN to build a list of DHCP leases and DNS
* entries then cross-reference them to show leases that don't have
* a corresponding DNS entry, and DNS entries that don't have a lease
**********************************************************************/
parse upper arg sort_type
if sort_type = '/?' then signal syntax
if sort_type = '/A' then
ip_sort = 1
else
ip_sort = 0
call RxFuncAdd 'SysLoadFuncs','RexxUtil','SysLoadFuncs'
call SysLoadFuncs
boot_drive = filespec('drive', value('comspec', ,'os2environment'))
named_file = boot_drive'\mptn\etc\namedb\named.dmp'
/* Add a few colours */
esc = '1B'x
yellow = esc || '[33;1m'
red = esc || '[31;1m'
white = esc || '[37;1m'
normal = esc || '[37;0m'
numeric digits 12
nssig_host.0 = 0
nssig_address.0 = 0
nssig_text.0 = 0
nssig_leased.0 = 0
dadmin_address.0= 0
dadmin_named.0 = 0
output.0 = 0
h = 0
do queued(); pull .; end /* Make sure queue is empty */
call do_nssig /* Process NSSIG -INT command */
call do_dadmin /* Process DADMIN -S command */
call do_xref /* Cross-reference both outputs */
call do_combine /* Make one list */
call do_sort /* Sort the list */
/* Output the list */
call SysCls
say left('-', 79, '-')
say '* Leased/Static has DNS entry ',
yellow'*'normal 'Leased/Static but no DNS entry ',
red'*'normal 'No lease'
say left('-', 79, '-')
say 'Address Registered Name'
say ' Description'
say left('--------------- ', 79, '-')
do h = 1 to output.0
parse value output.h with colour','address','host','text
say colour || left(address,15,' ') host text normal
end
exit 0
/**********************************************************************
* Run the NSSIG -INT command
* Read through the %ETC%\NAMED.DMP file created, for each line read:-
* IF not a comment line
* IF $ORIGIN entry
* keep track of $ORIGIN
* ELSE
* IF left char. is not a ' ' get the host name and the record type
* IF we don't have IP address for this host
* initialise stem entries
* get the host name and record type
* ELSE
* get the record type
* IF record type is 'A'
* get the hosts IP address
* IF record type is 'TXT'
* get the txt entry
**********************************************************************/
do_nssig:
say 'Running NSSIG'
call SysFileDelete named_file
'@NSSIG -INT >nul 2>&1'
call SysSleep(2)
say 'Reading input file 'named_file
rc = stream(named_file, 'c', 'open read')
if rc \= 'READY:' then
do
say 'Could not read input file. rc='rc
say 'Possible problem running NSSIG -INT'
exit 1
end
else
do while lines(named_file)
input = translate(linein(named_file), ' ', '09'x)
if left(input, 1) \= ';' then
do
if left(input, 7) = '$ORIGIN' then
parse value input with . origin
else
do
if left(input, 1) \= ' ' then
do
if nssig_address.h \= '' then
do
h = h + 1
nssig_address.0 = h
nssig_address.h = ''
nssig_text.h = ''
nssig_leased = 0
end
parse value input with nssig_host.h'IN' type more_data
parse value nssig_host.h with nssig_host.h .
nssig_host.h = nssig_host.h'.'origin
end
else
do
parse value input with .'IN' type more_data
end
end
if type = 'A' then
do
parse value more_data with nssig_address.h .
end
if type = 'TXT' then
do
parse value more_data with nssig_text.h';'.
parse value nssig_text.h with '"'nssig_text.h'"'
end
end
end
rc = stream(named_file, 'c', 'close')
if nssig_address.h = '' then nssig_host.0 = nssig_host.0 - 1
return
/**********************************************************************
* Run DADMIN -s command, put all output into a queue
* FOR each item in the queue
* IF item is LEASED, RESERVERD or N/A
* add it to stem
**********************************************************************/
do_dadmin:
say 'Running DADMIN'
'@dadmin -s | rxqueue'
if queued() < 6 then
do
say 'Not enough data returned by DADMIN'
exit 2
end
else
do 6; pull .; end /* Ignore the headers */
h = 0
do queued()
pull input
if pos('LEASED', input) \= 0 | pos('RESERVED', input) \= 0 | pos('N/A', input) \= 0 then
do
h = h + 1
dadmin_address.0 = h
parse value input with dadmin_address.h .
dadmin_named.h = 0
end
end
return
/**********************************************************************
* FOR every name found by NSSIG
* FOR every address found by DADMIN
* IF the two ip addresses are identical
* flag that NSSIG entry has a lease
* FOR every address found by DADMIN
* FOR every name found by NSSIG
* IF the two ip addreses are identical
* flag that DADMIN entry has a name
**********************************************************************/
do_xref:
do p1 = 1 to nssig_address.0
do p2 = 1 to dadmin_address.0
if nssig_address.p1 = dadmin_address.p2 then
do
nssig_leased.p1 = 1
iterate
end
end
end
do p1 = 1 to dadmin_address.0
do p2 = 1 to nssig_address.0
if dadmin_address.p1 = nssig_address.p2 then
do
dadmin_named.p1 = 1
iterate
end
end
end
return
/**********************************************************************
* Build 1 list for output from the 2 we already have
*
* initialise output list to be the same size as the NSSIG list
* FOR each item in the NSSIG list
* IF it has a lease
* it is normal in colour
* ELSE
* it is red
* add the address and name
* IF there is a TXT entry
* add the TXT entry
* FOR each item in the DADMIN list
* IF it doesn't have a DNS entry
* it is yellow in colour
* ELSE
* ignore it as it's already in the output list (from NSSIG)
* append a ',' so that sorting and output will work ok
**********************************************************************/
do_combine:
output.0 = nssig_address.0
do p1 = 1 to nssig_address.0
if nssig_leased.p1 = 1 then
output.p1 = normal','
else
output.p1 = red','
output.p1 = output.p1 || nssig_address.p1','nssig_host.p1','
if nssig_text.p1 \= '' then
output.p1 = output.p1'0d0a'x left(' ', 15, ' ') nssig_text.p1
end
do p2 = 1 to dadmin_address.0
if dadmin_named.p2 = 0 then
do
p1 = output.0 + 1
output.0 = p1
output.p1 = yellow','
end
else
iterate /* We already have this address */
output.p1 = output.p1 || dadmin_address.p2',' ','
end
return
/**********************************************************************
* Sort the output list
* Go the bubble sort!
*
* FOR every item in the output list
* FOR every item in the output list
* IF output is sorted by address
* get the first item - which is an ip address
* turn the ip address into a 12 digit number with no periods
* get the second item - which is also an ip address
* turn the ip address into a 12 digit number with no periods
* ELSE
* get the first item - which is a host name
* get the second item - which is also a host name
* IF first item is smaller than second item
* swap them
**********************************************************************/
do_sort: procedure expose output. ip_sort
do p1 = 1 to output.0
do p2 = 1 to output.0
if ip_sort then
do
parse value output.p1 with .','item1','.
parse value item1 with a1'.'a2'.'a3'.'a4
item1 = right(a1,3,'0') || right(a2,3,'0') || right(a3,3,'0') || right(a4,3,'0')
parse value output.p2 with .','item2','.
parse value item2 with a1'.'a2'.'a3'.'a4
item2 = right(a1,3,'0') || right(a2,3,'0') || right(a3,3,'0') || right(a4,3,'0')
end
else
do
parse value output.p1 with .','.','item1','.
parse value output.p2 with .','.','item2','.
end
if item1 < item2 then
do
item_tmp = output.p1
output.p1 = output.p2
output.p2 = item_tmp
end
end
end
return
/**********************************************************************
* Show the syntax
**********************************************************************/
syntax:
say 'DUMPER [/A]'
say ' /A Sort by address'
say ''
say ' Default is sort by name'
exit