Page 2 of 2 <12
Topic Options
#91939 - 2003-04-19 03:15 PM Re: COM access to MS DHCP server
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
We use QIP also. All that data is stored in a SQL database - Oracle in our case.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#91940 - 2003-04-21 04:45 PM Re: COM access to MS DHCP server
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
ok... here is a modified version that only requires the server IP as a parameter... as it will automatically enums alls the scopes/superscopes present on the server

The optional IP parameter will isolate the return to the Info for just that IP's info

code:
 
break on

$return = EnumMAC('164.51.39.140','164.51.163.134')
for $x=0 to ubound($return,2)
? $return[0,$x] + ' ' + $return[1,$x] + ' ' + $return[2,$x]
next

Function EnumMAC($server, Optional $ip)
DIM $DHCPCMD, $command, $line, $x, $addr, $host, $mac, $scope, $superscope
DIM $arrTemp[2,0]

$x = 0
$command = 'cmd /c '+@scriptdir+'\dhcpcmd.exe '+ $server +' getsuperscopetable | find "Subnet address"'
$superscope = WSHPipe($command,1)

for each $scope in $superscope
$subnet = trim(split($scope,'=')[1])
$command = 'cmd /c '+@scriptdir+'\dhcpcmd.exe '+ $server +' enumclients ' + $subnet+' -h'
if $ip
$command = $command + ' | find "' + $ip + '"'
endif
$output = WSHPipe($command,1)
For each $line in $output
if val(left($line,1))
$arrTemp[0,$x] = trim(substr($line,4,15))
$arrTemp[1,$x] = split(trim(substr($line,21,16)),'.')[0]
$arrTemp[2,$x] = trim(substr($line,38,17))
$x = $x +1
redim preserve $arrTemp[2,$x]
endif
next
next
if $x
redim preserve $arrTemp[2,$x-1]
$EnumMAC = $arrTemp
else
exit (1)
endif
EndFunction
;********************************************************************************************
Function WshPipe($ShellCMD, OPTIONAL $NoEcho)
Dim $WshShell, $oExec, $AllOutput, $Exit, $WshExitCode
$WshErrorMsg=""
$WshShell=CreateObject("WScript.Shell")
$oExec=$WshShell.Exec($ShellCMD)
While $Exit<>1
Dim $Output
Select
Case Not $oExec.StdOut.AtEndOfStream $Output=$oExec.StdOut.ReadAll
Case Not $oExec.StdErr.AtEndOfStream $Output=$oExec.StdErr.ReadAll
$WshErrorMsg = $Output
Case 1 $Output=-1
EndSelect
If $Output=-1
If $oExec.Status=1 $Exit=1 Endif
Else
If $NoEcho<>1 ? $Output Endif
$AllOutput = $AllOutput + $Output
Endif
Loop
$WshExitCode=$oExec.ExitCode
$WshPipe=split($AllOutput,chr(10))
Exit($WshExitCode)
EndFunction

_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#91941 - 2003-04-21 10:29 PM Re: COM access to MS DHCP server
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
and here is the latest and greatest... a number of bug fixes included. requires the WshPipe() UDF and dhcpcmd.exe from reskit
code:
 
$dump=EnumMAC('192.168.0.2')
for $item = 0 to ubound($dump,2)
? $dump[0,$item] +' '+ $dump[2,$item] +' '+ $dump[1,$item]
next

$mac = EnumMAC('192.168.0.2','192.168.0.103')[2,0]
if not @error
? $mac
shell 'cmd /c \\server\tools\wol.exe ' + $mac +' > nul'
endif

code:
 
Function EnumMAC($server, Optional $ip)
DIM $DHCPCMD, $command, $line, $x, $addr, $host, $mac, $scope, $superscope
DIM $arrTemp[2,0]

$DHCPCMD = '\\a06\logon\tools\dhcpcmd.exe'

$x = 0
$command = 'cmd /c ' + $DHCPCMD +' '+ $server +' getsuperscopetable | find "Subnet"'
$superscope = WSHPipe($command,1)
for each $scope in $superscope
$subnet = trim(split(split($scope,'=')[1],chr(13))[0])
if len($subnet)
$command = 'cmd /c ' + $DHCPCMD +' '+ $server +' enumclients ' + $subnet+' -h'
if $ip
$command = $command + ' | find "' + $ip + '"'
endif
$output = WSHPipe($command,1)
For each $line in $output
if val(left($line,2))
$line=split(split($line,chr(9))[1],chr(13))[0]
$arrTemp[0,$x] = trim(substr($line,1,16))
$arrTemp[1,$x] = split(trim(substr($line,17,16)),'.')[0]
$arrTemp[2,$x] = trim(substr($line,35,13))
$x = $x + 1
redim preserve $arrTemp[2,$x]
endif
next
endif
next
if $x
redim preserve $arrTemp[2,$x-1]
$EnumMAC = $arrTemp
else
exit (1)
endif
EndFunction

_________________________
How to ask questions the smart way <-----------> Before you ask

Top
Page 2 of 2 <12


Moderator:  Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 581 anonymous users online.
Newest Members
fgarcia, Viginette, ManuvdWielNL, Sir_Barrington, batdk82
17889 Registered Users

Generated in 0.051 seconds in which 0.025 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org