系统:WIN2003,DHCP服务器。我现在需要编程实现自动新建保留客户端、修改已有保留客户端的MAC等等,请问是否能实现,如何能实现?
谢谢!问题解决追加分数50!

解决方案 »

  1.   

    就是保存mac,简单处理,无需高深编程,直接批处理先ping扫内网,直接arp -a不都有了
      

  2.   

    批处理执行太慢了,大概要近5秒才能添加一个保留客户端。我目前为止需要添加的保留客户端已经有8000个了,并且还在不断增加中,并且不止一个作用域,所以批处理已不是最佳解决方案了。我在MSDN上看到有相关的API函数,但是本人比较愚钝,看不太明白,所以仍然不会用。所以才在此请教一下明白DHCP相关API函数的高手,这些函数到底如何使用,我的问题是否能用这些函数解决?另外,感谢just4,感谢你的热心,我的上一个问题,也是承你的热心帮助,基本得到解决,就是今天这个问题的批处理解决方式:http://topic.csdn.net/u/20100121/17/044c87e8-536f-47af-807a-ba4f7ae0ea5a.html
      

  3.   

    从下面这些函数查吧。
    Platform SDK: Dynamic Host Configuration Protocol (DHCP) 
    DHCP Server Management API Functions
    The following functions comprise the DHCP Server Management API library.Function Description 
    DhcpCreateClientInfo Creates a client information record on the DHCP server. 
    DhcpDeleteClientInfo Deletes a client information record from the DHCP server. 
    DhcpEnumSubnetClients Returns an enumerated list of clients with served IP addresses in the specified subnet. 
    DhcpEnumSubnets Returns an enumerated list of subnets defined on the DHCP server. 
    DhcpGetClientInfo Returns information about a specific DHCP client. 
    DhcpGetOptionValue Retrieves a DHCP option value (the option code and associated data) for a particular scope. 
    DhcpGetServerBindingInfo Returns endpoint bindings set on the DHCP server. 
    DhcpGetSubnetInfo Returns information on a specific subnet. 
    DhcpGetVersion Returns the major and minor version numbers of the DHCP server. 
    DhcpRpcFreeMemory Frees a block of buffer space returned as a parameter by the Remote Procedure Call (RPC) service. 
    DhcpSetClientInfo Sets information on a client whose IP address lease is administrated by the DHCP server. 
    DhcpSetServerBindingInfo Sets endpoint bindings for the DHCP server. 比如DhcpEnumSubnetClients
    The DhcpEnumSubnetClients function returns an enumerated list of clients with served IP addresses in the specified subnet.DWORD DHCP_API_FUNCTION DhcpEnumSubnetClients(
      DHCP_CONST WCHAR* ServerIpAddress,
      DHCP_IP_ADDRESS SubnetAddress,
      DHCP_RESUME_HANDLE* ResumeHandle,
      DWORD PreferredMaximum,
      LPDHCP_CLIENT_INFO_ARRAY* ClientInfo,
      DWORD* ClientsRead,
      DWORD* ClientsTotal
    );Parameters
    ServerIpAddress 
    [in] Unicode string that specifies the IP address of the DHCP server. 
    SubnetAddress 
    [in] DHCP_IP_ADDRESS value that contains the subnet ID. See RFC 950 for more information about subnet ID. 
    ResumeHandle 
    [in, out] Pointer to a DHCP_RESUME_HANDLE value that identifies the enumeration operation. Initially, this value should be zero, with a successful call returning the handle value used for subsequent enumeration requests. For example, if PreferredMaximum is set to 1000 bytes, and 2000 bytes worth of subnet client information structures are stored on the server, the resume handle can be used after the first 1000 bytes are retrieved to obtain the next 1000 on a subsequent call, and so forth. 
    PreferredMaximum 
    [in] Specifies the preferred maximum number of bytes of subnet client information structures to return. If the number of remaining unenumerated options (in bytes) is less than this value, then that amount will be returned. 
    The minimum value is 1024 bytes (1KB), and the maximum value is 65536 bytes (64KB); if the input value is greater or less than this range, it will be set to the maximum or minimum value, respectively.ClientInfo 
    [out] Pointer to a DHCP_CLIENT_INFO_ARRAY structure that contains information on the clients served under this specific subnet. If no clients are available, this field will be null. 
    ClientsRead 
    [out] Pointer to a DWORD value that specifies the number of clients returned in ClientInfo. 
    ClientsTotal 
    [out] Pointer to a DWORD value that specifies the number of clients for the specified subnet that have not yet been enumerated.
    Note  This value is set to the correct value during the final enumeration call; however, prior calls to this function set the value as "0x7FFFFFFF".Return Values
    This function returns ERROR_MORE_DATA upon a successful call. The final call to this method with the last set of subnet clients returns ERROR_SUCCESS. Otherwise, it returns one of the DHCP Server Management API Error Codes.
    Res
    This function requires host byte ordering for all DHCP_IP_ADDRESS values in parameter structures.Requirements
    Server Requires Windows Server 2003, Windows 2000 Server, or Windows NT Server 4.0. 
    Header Declared in Dhcpsapi.h.
     
    Library Link to Dhcpsapi.lib.
     
    DLL Requires Dhcpsapi.dll.  不过个人还是对批处理比较感兴趣。
      

  4.   

    谢谢,我对批处理也比较有兴趣,虽然我现在从事的并不是软件开发相关的工作,这次只是因为日常工作需要,自己开发一个小工具,但是,正如我前面说的,我需要添加的保留客户端太多了,并且还在不断增加中,并且还不只一个作用域,批处理执行又太慢了,所以对我而言,批处理就不是最佳选择了。而MSDN上的资料,我也看过一些,因为本人的英文水平比较差,所以看的不是很明白。如果能给我提供一些函数的用法,尤其其中的一些参数,本人不胜感激。比如DhcpCreateClientInfo,编译时虽然没有报错了,但是在DHCP上并没有看到执行结果添加的保留客户端。有劳给我讲解一下,谢谢!
      

  5.   

    使用API的麻烦之处就在这里。参数要仔细研究。
    我也没做过,一样不会,要慢慢试才行,这个属于比较偏的,估计做的人比较少。你再试试能不能找到一些开源的代码吧。
      

  6.   

    非常感谢!
    网上相关的东西也少,翻来覆去也总是那几个函数,不是copy的MSDN,就是语焉不详,想必更没有源码了。我再多试试,有什么问题再向你请教,还望不吝赐教!
      

  7.   

    试下HOOK DhcpDeleteClientInfo()行不行.