DHCP Server API? 
Author Message
 DHCP Server API?

I want to be able to query the DHCP Server on our network to get scope
information for each scope on the server.  Any API's to do this.  Any help
appreciated.


Tue, 02 Dec 2003 11:24:43 GMT  
 DHCP Server API?
You can reference the sample code at
http://www.mvps.org/vbnet/code/network/index.html
The API DhcpRequestParams may meet your needs.


Tue, 02 Dec 2003 11:56:50 GMT  
 DHCP Server API?
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.

Quote:
> You can reference the sample code at
> http://www.mvps.org/vbnet/code/network/index.html
> The API DhcpRequestParams may meet your needs.



Tue, 02 Dec 2003 12:13:13 GMT  
 DHCP Server API?
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.
: >
: >
:
:



Wed, 03 Dec 2003 06:16:31 GMT  
 DHCP Server API?

Thanks Olsen, I will check it out.

  Use DHCP Objects

  /Olsen



  > 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.
  > : >
  > : >
  > :
  > :
  >
  >



Sun, 07 Dec 2003 11:01:20 GMT  
 DHCP Server API?

Worked great, but no count or enumeration of Active Leases.  Any furthor ideas?

  Thanks Olsen, I will check it out.

    Use DHCP Objects

    /Olsen



    > 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.
    > : >
    > : >
    > :
    > :
    >
    >



Mon, 08 Dec 2003 10:59:33 GMT  
 DHCP Server API?
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.
> : >
> : >
> :
> :



Wed, 10 Dec 2003 13:50:40 GMT  
 DHCP Server API?
Thanks Dave, was hoping I wouldn't have to resort to this, but your code
worked great.  Thanks for the input.

Quote:
> 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
> >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



> > 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.
> > : >
> > : >
> > :
> > :



Sat, 13 Dec 2003 13:43:02 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. APi for DHCP server

2. DHCP Server

3. API/COM for DHCP ??

4. VB5 - DHCP server

5. API/COM for DHCP ??

6. DHCP & API

7. DHCP server programming

8. API/COM for DHCP ??

9. DHCP Server

10. DHCP & API

11. DHCP server

12. DHCP Server Modification Tool

 

 
Powered by phpBB® Forum Software