George,
I have done this, but not by using an API.
there is an API to do it, but it is a MS one that they use for another
product, so no info, references etc.......
What I did is this..
----------------------------SNIP
HERE-------------------------------------------------
frmMain
' This program relies on DHCPCMD.exe being installed AND in the users path
' ****
' ****
' It is ESSENTIAL that the version of DHCPCMD.exe used is at least 4.00
' ****
' ****
Dim DHCPServer As String
Private Sub Form_Load()
mnuFile.Enabled = False
frmDHCP.Show
frmDHCP.Refresh
RefreshScopes ' Initiate DHCP scope extraction
mnuFile.Enabled = True
End Sub
Private Sub cmdEnum_Click()
' Create the batch file used to enumerate the information
cmd = "dhcpcmd 10.1.1.21 enumclients " &
lstScopes.List(lstScopes.ListIndex) & " -h >c:\temp\dhcpclients.txt"
Open "c:\temp\getclients.bat" For Output As #1
Print #1, cmd
Close 1
Shell "c:\temp\getclients.bat", vbHide
cmdExtract2.Enabled = True
' Wait 4 seconds after running the command for the results to be
returned.
' Increase this number if the DHCP server is on a slow link
a = Time
Do Until Time > DateAdd("s", 4, a)
DoEvents
Loop
' Parse the txt file for information required. In this case it is the
DHCP Scopes.
cmdExtract2_Click
lblClients = lstClients.ListCount & " Clients"
lblClients.Refresh
End Sub
Private Sub cmdExportScope_Click()
' Export the information contained in the list box to a text file
lblClients = "Exporting... please wait"
lblClients.Refresh
FileName = "c:\temp\" & lstScopes.Text & ".txt"
Open FileName For Output As #3
For lp = 0 To lstClients.ListCount - 1
Print #3, lstClients.List(lp)
Next lp
Close 3
MsgBox "Extract complete. File saved to c:\temp\" & lstScopes.Text &
".txt"
lblClients = lstClients.ListCount & " Clients"
lblClients.Refresh
End Sub
Private Sub cmdExtract_Click()
' Get scope data and put in list box
Open "c:\temp\scopes.txt" For Input As #1
Do Until EOF(1)
Line Input #1, varData
If Left(varData, 17) = "Subnet address = " Then
lstScopes.AddItem Right(varData, Len(varData) - 17)
End If
Loop
Close 1
End Sub
Private Sub cmdExtract2_Click()
' Parse information in extracted text file
lstClients.Clear
Open "c:\temp\dhcpclients.txt" For Input As #1
' CHANGE: removed version info from DHCP Server info line to allow
future versions
junk1 = "DHCP Server version" ' 4.1"
junk2 = "Command successfully completed."
Do Until EOF(1)
Line Input #1, varData
' 19 chars is the length of the above two 'junk' lines
If Left(varData, Len(junk1)) <> junk1 And Left(varData,
Len(junk2)) <> junk2 Then
varTab = InStr(1, varData, Chr(9))
num = Mid(varData, 1, varTab - 1)
varRemainder = Right(varData, Len(varData) - varTab - 1)
IP = Trim(Left(varRemainder, 17))
varRemainder = Right(varData, Len(varData) - varTab - 18)
varSpace = InStr(1, varRemainder, " ")
varHost = Trim(Left(varRemainder, varSpace))
varMAC = Trim(Right(varRemainder, Len(varRemainder) -
varSpace))
varNewData = IP & "," & varHost & "," & varMAC
lstClients.AddItem varNewData
End If
Loop
Close 1
End Sub
Private Sub cmdScopes_Click()
lstScopes.Clear
' Create the batch file used to enumerate the information
cmd = "dhcpcmd " & DHCPServer & " getsuperscopetable
Quote:
>c:\temp\scopes.txt"
Open "c:\temp\getscopes.bat" For Output As #1
Print #1, cmd
Close 1
' Run the batch file
Shell "c:\temp\getscopes.bat", vbHide
cmdExtract.Enabled = True
End Sub
Sub RefreshScopes()
' Ask the user for the DHCP Servers IP Address. This is a modification
that was added to
' allow this program to be used in a non XXXX environment.
If DHCPServer = "" Then
DHCPServer = InputBox("Enter your DHCP Server's IP Address", "Input
Required", "10.1.1.21")
End If
lblScopes = "Enumerating..."
lblScopes.Refresh
cmdScopes_Click
frmDHCP.Refresh
' Wait 4 seconds after running the command for the results to be
returned.
' Increase this number if the DHCP server is on a slow link
a = Time
Do Until Time > DateAdd("s", 4, a)
DoEvents
Loop
cmdExtract_Click
lblScopes = lstScopes.ListCount & " Scopes"
lblScopes.Refresh
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Unload frmExport
Unload Me
End
End Sub
Private Sub lstScopes_Click()
RefreshClients
End Sub
Sub RefreshClients()
lblClients = "Enumerating... please wait"
lblClients.Refresh
cmdEnum_Click
End Sub
Private Sub mnuClients_Click()
RefreshClients
End Sub
Private Sub mnuExit_Click()
End
End Sub
Private Sub mnuExportAll_Click()
frmExport.Show vbModal
End Sub
Private Sub mnuExportSelected_Click()
cmdExportScope_Click
End Sub
Private Sub mnuScopes_Click()
RefreshScopes
End Sub
frmExport
Private Sub cmdClose_Click()
Unload Me
End Sub
Private Sub cmdExport_Click()
Open txtOutput For Output As #2
If optExtract1 = True Then
For a = 0 To frmDHCP.lstClients.ListCount - 1
varData = frmDHCP.lstClients.List(a)
Print #2, varData
Next a
Else
For a = 0 To frmDHCP.lstScopes.ListCount - 1
frmDHCP.lstScopes.ListIndex = a
frmDHCP.Refresh
For b = 0 To frmDHCP.lstClients.ListCount - 1
varData = frmDHCP.lstClients.List(b)
Print #2, varData
Next b
Next a
End If
Close 2
End Sub
Worked great, but no count or enumeration of Active Leases. Any furthor
ideas?
Thanks Olsen, I will check it out.
Use DHCP Objects
/Olsen
Quote:
> No "their", alas. Just one lone soul amid a sea of uncompleted demos.
<<g>>
> --
> Randy Birch
> MVP Visual Basic
> http://www.mvps.org/vbnet/
> Please respond only to the newsgroups so all can benefit.
> : I check their site daily, and they have samples to find out what the
DHCP
> : server is. I already know that. I want to talk to the server, and get
a
> : list of scopes, and then enumerate the scopes to find out devices in
that
> : scope, and the exceptions for each scope.
> : > You can reference the sample code at
> : > http://www.mvps.org/vbnet/code/network/index.html
> : > The API DhcpRequestParams may meet your needs.
> : >
> : >
> :
> :