Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

DhcpEnumSubnetClients (dhcpsapi)
 
.
Summary
TODO - DhcpEnumSubnetClients collects all clients in a specific subnet (clientinfo -> reservations)

C# Signature:

[DllImport("dhcpsapi.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern uint DhcpEnumSubnetClients(
    string ServerIpAddress,
    uint SubnetAddress,
    ref uint ResumeHandle,
    uint PreferredMaximum,
    out IntPtr ClientInfo,
    ref uint ElementsRead,
    ref uint ElementsTotal);

VB Signature:

Declare Unicode Function DhcpEnumSubnetClients Lib "Dhcpsapi" (ByVal ServerIpAddress As String, ByVal SubnetAddress As Integer, ByRef ResumeHandle As Integer, ByVal PreferredMaximum As Integer, ByRef ClientInfo As IntPtr, ByRef ClientsRead As Integer, ByRef ClientsTotal As Integer) As Integer

User-Defined Types:

DHCP_CLIENT_INFO_ARRAY

Alternative Managed API:

Do you know one? Please contribute it!

Notes:

None.

Tips & Tricks:

Please add some!

Sample Code:

Imports System.Runtime.InteropServices

Declare Unicode Function DhcpEnumSubnetClients Lib "dhcpsapi" (ByVal ServerIpAddress As String, ByVal SubnetAddress As Int32, ByRef ResumeHandle As IntPtr, ByVal PreferredMaximum As Integer, ByRef ClientInfo As IntPtr, ByRef ClientsRead As Integer, ByRef ClientsTotal As Integer) As Integer

    <StructLayout(LayoutKind.Sequential)> _
    Private Structure DHCP_IP_ARRAY
    Dim NumElements As Int32
    Dim Elements As IntPtr
    End Structure

    <StructLayout(LayoutKind.Sequential)> _
   Private Structure DHCP_CLIENT_INFO_ARRAY

    Dim NumElements As Integer
    Dim Clients As IntPtr

    End Structure

    <StructLayout(LayoutKind.Sequential)> _

Private Structure DHCP_CLIENT_INFO

    Dim ClientIpAddress As Int32
    Dim SubnetMask As Int32
    Dim ClientHardwareAddress As DHCP_BINARY_DATA

    <MarshalAs(UnmanagedType.LPWStr)> _
        Dim ClientName As String

    <MarshalAs(UnmanagedType.LPWStr)> _
    Dim ClientComment As String

    Dim ClientLeaseExpires As Date_Time
    Dim OwnerHost As DHCP_HOST_INFO

    End Structure

    <StructLayout(LayoutKind.Sequential)> _
    Private Structure DHCP_BINARY_DATA
    Dim DataLength As Int32
    Dim Data As IntPtr
    End Structure

    <StructLayout(LayoutKind.Sequential)> _
   Private Structure Date_Time

    <MarshalAs(UnmanagedType.U4)> _
    Dim dwLowDateTime As UInt32

    <MarshalAs(UnmanagedType.U4)> _
    Dim dwHighDateTime As UInt32

    End Structure

    <StructLayout(LayoutKind.Sequential)> _

Private Structure DHCP_HOST_INFO

    Dim IpAddress As Int32

    <MarshalAs(UnmanagedType.LPWStr)> _
    Dim NetBiosName As String

    <MarshalAs(UnmanagedType.LPWStr)> _
    Dim HostName As String

    End Structure

public sub ListSubnetClients()

        Dim Client_Array As DHCP_CLIENT_INFO_ARRAY
        Dim DHCP_Clients() As DHCP_CLIENT_INFO

        Dim i,j As Int16

        Dim pt As IntPtr

        Dim Read_Clients, Total_Clients As Int32
        Dim Error_Code As Int32
        Dim Rem_Handle As IntPtr
        Dim Scope_I As Int32

'Scope_I = "10.0.3.0"

        Scope_I = 167772928    

        'Call dhcpsapi
        Error_Code = DhcpEnumSubnetClients(DHCP_Server, Scope_I, Rem_Handle, 65537, pt, Read_Clients, Total_Clients)

        Client_Array = Marshal.PtrToStructure(pt, GetType(DHCP_CLIENT_INFO_ARRAY))

        ReDim DHCP_Clients(Client_Array.NumElements - 1)

       For i = 0 To Client_Array.NumElements - 1
        pt = Marshal.ReadIntPtr(Client_Array.Clients, j)
        DHCP_Clients(i) = Marshal.PtrToStructure(pt, GetType(DHCP_CLIENT_INFO))
        pt = IntPtr.Zero
        j = j + 4
        Next i

end sub

Documentation

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

 
Access PInvoke.net directly from VS:
Terms of Use
Find References
Show Printable Version
Revisions