Page 1 of 2 12>
Topic Options
#91919 - 2003-04-17 07:15 PM COM access to MS DHCP server
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
Is there a COM or LDAP method into the MS DHCP server? I need to retreive specific MAC addresses from the pool.

i.e. make a function to pass a name or IP and return the MAC address.

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

Top
#91920 - 2003-04-17 07:54 PM Re: COM access to MS DHCP server
Breaker Offline
Hey THIS is FUN
*****

Registered: 2001-06-15
Posts: 268
Loc: Yorkshire, England
Arp?
_________________________
================================================
Breaker


Top
#91921 - 2003-04-17 07:55 PM Re: COM access to MS DHCP server
Breaker Offline
Hey THIS is FUN
*****

Registered: 2001-06-15
Posts: 268
Loc: Yorkshire, England
Sorry.

I meant, nope, sorry, never come across one. Would it help you to shell out to ARP, and parse the output?

Bit curt, there. I apologise.

[ 17. April 2003, 19:56: Message edited by: Breaker ]
_________________________
================================================
Breaker


Top
#91922 - 2003-04-17 08:08 PM Re: COM access to MS DHCP server
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
the problem is, that if the target PC that I wish to get the MAC of, has been off long enough, the arp cache on whatever PC queried, will not have it.

I have found a kludge of a solution..., but there has to be a better way:

code:
 
$Mac = GetMac('wheelerc_2nd', 'ada06')
shell '\\a06\logon\tools\wol.exe ' + $mac


Function GetMac($ip, $dhcpServer)
DIM $logs, $found, $file, $arr

$logs=enumdir('\\'+$dhcpServer+'\admin$$\system32\dhcp\','dhcpsrvlog.*',1)
$found=0
for each $file in $logs
if $found=0
if open(1,$file,2)=0
$line=readline(1)
while @error=0 and $found=0
if instr($line,$ip) and (instr($line,'Assign') or instr($line,'renew'))
$arr =split($line,',')
$GetMac = $arr[ubound($arr)]
$found = 1
endif
$line=readline(1)
loop
$=close(1)
endif
endif
next
if $GetMac='' exit (1) endif
endfunction

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

Top
#91923 - 2003-04-18 12:07 AM Re: COM access to MS DHCP server
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
AAARRRGGGG.... It hurts, it hurts...

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/adschema/ad/win2k_c_dhcpclass.asp
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#91924 - 2003-04-18 03:02 AM Re: COM access to MS DHCP server
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
[Smile] [Smile] [Smile]

Can I request a UDF for this? Might come in handy at some point.
_________________________
There are two types of vessels, submarines and targets.

Top
#91925 - 2003-04-18 03:37 AM Re: COM access to MS DHCP server
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
Sure... just as soon as someone else comes up with it. I don't even know where to begin...
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#91926 - 2003-04-18 04:46 AM Re: COM access to MS DHCP server
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Would this help: Find DHCP and DHCP information
_________________________
There are two types of vessels, submarines and targets.

Top
#91927 - 2003-04-18 05:51 AM Re: COM access to MS DHCP server
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
from what it reads, is that DHCP config is in ADSI, but the lease info isn't...

I guess I'm stuck with what I found in the log files...
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#91928 - 2003-04-18 10:58 PM Re: COM access to MS DHCP server
Stevie Offline
Starting to like KiXtart
*****

Registered: 2002-01-09
Posts: 199
IIRC, you can get that info with DHCPCMD with the EnumClients option.
_________________________
Stevie

Top
#91929 - 2003-04-19 02:13 AM Re: COM access to MS DHCP server
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
show me...
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#91930 - 2003-04-19 02:57 AM Re: COM access to MS DHCP server
Stevie Offline
Starting to like KiXtart
*****

Registered: 2002-01-09
Posts: 199
You live in Missouri?

Just ran this on an XP client against a Win2K DHCP server:

dhcpcmd 192.168.1.10 enumclients 192.168.1.0 -v (You can also use -h for just the hardware info)

The first IP is the DHCP Server, the second is the subnet from which you wish to retrieve the client info.

The results are as follows:
code:
DHCP Server version 5.5
Num Client info read = 2.
Total Client count = 2.
ClientInfo :
IP Address = 192.168.1.200.
SubnetMask = 255.255.255.0.
Client Hardware Address = 00-80-ad-78-92-0e.
Name = ws-main.deadminstrel.com.
Comment = (null).
Type = DHCP
Expires = 04/19/2003 22:46:10.
Owner Host IP Address = 192.168.1.10.
Owner Host NetBios Name = SVR.
Owner Host Name = (null).
ClientInfo :
IP Address = 192.168.1.203.
SubnetMask = 255.255.255.0.
Client Hardware Address = 00-80-64-16-0a-50.
Name = (null).
Comment = (null).
Type = DHCP
Expires = 04/20/2003 07:54:35.
Owner Host IP Address = 192.168.1.10.
Owner Host NetBios Name = SVR.
Owner Host Name = (null).
Command successfully completed.

The only unusual thing that happened was I got an "unable to retrieve DHCP server version" the first time I ran it. After I ran 'dhcpcmd 192.168.1.10 GetVersion' it returned the version and then the enumclients command ran successfully. After which, I couldn't reproduce the error. Maybe just a fluke.

[ 19. April 2003, 03:01: Message edited by: Steve B ]
_________________________
Stevie

Top
#91931 - 2003-04-19 03:06 AM Re: COM access to MS DHCP server
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
you are the man....

I'll get somthing together Monday

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

Top
#91932 - 2003-04-19 03:35 AM Re: COM access to MS DHCP server
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
I can smell a nice little UDF coming up that returns an array of DHCP clients, either 1-D for just the IP numbers, or 2-D with all the other info, too.
_________________________
There are two types of vessels, submarines and targets.

Top
#91933 - 2003-04-19 05:19 AM Re: COM access to MS DHCP server
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
I'm working on it... but the damned multi dim array is kicking my butt
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#91934 - 2003-04-19 05:59 AM Re: COM access to MS DHCP server
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Radimus, This would be a perfect application for a HASH or Dictionary object. Each object would be a client with numerous keys that reference the unique data of each client.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#91935 - 2003-04-19 06:09 AM Re: COM access to MS DHCP server
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
aaarrrggghhhh, you are hurting me.....
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#91936 - 2003-04-19 06:30 AM Re: COM access to MS DHCP server
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
ok.... Here it is, beat it up and see what you think. Suggestions are appreciated. Efficiency is king...

without the optional IP parameter it will return ALL the info for ALL leases. The IP parameter will limit the return to just that IP.

obviously, this requires a MS DHCP server and the dhcpcmd.exe tool from the reskit in @scriptdir... I may change it to so %path% would be sufficient, but that is no big deal
http://www.dynawell.com/reskit/microsoft/win2000/dhcpcmd.zip

code:
 
break on

$return = EnumMAC('192.168.110.2', '192.168.110.0','192.168.110.12')
for $x=0 to ubound($return,2)
? 'IP: ' + $return[0,$x]
? 'Host: ' + $return[1,$x]
? 'MAC: ' + $return[2,$x]
next

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

$x = 0
$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,37,16))
$x = $x +1
redim preserve $arrTemp[2,$x]
endif
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

I'll eventually post this over to UDF after if gets beaten up a while.

Jens, this might be a nice addon to KSMS

[ 19. April 2003, 06:32: Message edited by: Radimus ]
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#91937 - 2003-04-19 07:14 AM Re: COM access to MS DHCP server
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
first change I need to do to this is to remove the subnet portion, and have it automagically enum all the subnets that may be on the server.

It may be possible to enum all the DHCP servers or accept multiple servers as an array, but that shouldn't be a big issue.

And I possibly could detect the local dhcp server, but this has just as much potential for remote servers as local servers, so that isn't very important
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#91938 - 2003-04-19 09:04 AM Re: COM access to MS DHCP server
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
Sounds cool Radimus.

We use Lucent QIP, so I can't test or play with this for you.

Top
Page 1 of 2 12>


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

Who's Online
0 registered and 641 anonymous users online.
Newest Members
fgarcia, Viginette, ManuvdWielNL, Sir_Barrington, batdk82
17889 Registered Users

Generated in 0.038 seconds in which 0.014 seconds were spent on a total of 13 queries. Zlib compression enabled.

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