morlix has asked for the wisdom of the Perl Monks concerning the following question:

hello monks,

i have an dhcp server on which i defined a pool like this:
subnet 192.168.125.0 netmask 255.255.255.0 { range 192.168.125.200 192.168.125.250; option routers 192.168.125.10; option domain-name "pillepalle.de"; option domain-name-servers 192.168.125.10, 192.168.101.15; option option-222 "http://pillepalle.de:8080"; }
you can see that i have a user-defined option (option-222). Now i want to get the value of these option from within a windows pc via perl code.

very thanks for every hint.

Replies are listed 'Best First'.
Re: getting non-default dhcp option value
by gargle (Chaplain) on Sep 12, 2005 at 11:44 UTC
Re: getting non-default dhcp option value
by NetWallah (Canon) on Sep 12, 2005 at 16:08 UTC
    To get custom DHCP options in a Windows client, you will need to make some WIN32 API calls.

    From the Microsoft KB article
    Windows 2000
    The DHCP Client service in Windows 2000 has been updated from Windows NT 4.0. Windows 2000 clients must make a DhcpRequestParams API call to request custom parameters. The DHCP client stores data that is obtained from a DHCP server in its local cache. If the DHCP client cache contains all of the data that is requested in the pRecdParams array of a DhcpRequestParams function call, the client returns data from its cache.

    The article contains link to some C code.

         "Man cannot live by bread alone...
             He'd better have some goat cheese and wine to go with it!"

Re: getting non-default dhcp option value
by sh1tn (Priest) on Sep 12, 2005 at 10:41 UTC
    Maybe something like:
    my $data; my $subnet; my $ip = qr/((?:\d{1,3}\.){3}\d{1,3})/; while(<DATA>){ /subnet\s+$ip\s+netmask\s+$ip/ and $subnet = $1 and $data->{"subnet:$subnet"} = { ip => $1, mask => $2, }; /range\s+$ip\s+$ip/ and $data->{"subnet:$subnet"}{range} = { ip => $1, mask => $2, }; /option\s+routers\s+$ip/ and $data->{"subnet:$subnet"}{routers} = { ip => $1 }; /option\s+domain-name\s+"(\S+)"/ and $data->{"subnet:$subnet"}{'domain-name'} = { 'hostname', $1 }; /option\s+domain-name-servers\s+(.+?)\W*$/ and $data->{"subnet:$subnet"}{'domain-name-servers'} = { 'hostname', [ split /,/, $1 ] }; /option\s+option-222\s+"(\S+)"/ and $data->{"subnet:$subnet"}{'option-222'} = { 'hostname', $1 }; } use Data::Dumper;die Dumper($data); __DATA__ subnet 192.168.125.0 netmask 255.255.255.0 { range 192.168.125.200 192.168.125.250; option routers 192.168.125.10; option domain-name "pillepalle.de"; option domain-name-servers 192.168.125.10, 192.168.101.15; option option-222 "http://pillepalle.de:8080"; } __END__ stdout: $VAR1 = { 'subnet:192.168.125.0' => { 'routers' => { 'ip' => '192.168. +125.10' }, 'ip' => '192.168.125.0', 'domain-name-servers' => { 'host +name' => [ + '192.168.125.10', + ' 192.168.101.15' + ] }, 'domain-name' => { 'hostname' => + 'pillepalle.de' }, 'range' => { 'ip' => '192.168.12 +5.200', 'mask' => '192.168. +125.250' }, 'option-222' => { 'hostname' => +'http://pillepalle.de:8080' }, 'mask' => '255.255.255.0' } };


      i dont understand how this could help me.

      i want to get the value of the option from within the windows pc who got his ip from the dhcp. This pc should not have access to the config file.
Re: getting non-default dhcp option value
by sgifford (Prior) on Sep 12, 2005 at 15:41 UTC
    Are you writing a DHCP client, or are you just running on a server that has its own DHCP client and you want to get the options from that client?
      i just want to get the value of this variable. i dont know if windows saves every option it gets from the dhcp server.