The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Win32::IPConfig - Windows NT/2000 IP Configuration Settings

SYNOPSIS

    use Win32::IPConfig;

    $host = shift || "";
    if ($ipconfig = Win32::IPConfig->new($host)) {
        print "hostname=", $ipconfig->get_hostname, "\n";
        print "domain=", $ipconfig->get_domain, "\n";
        print "nodetype=", $ipconfig->get_nodetype, "\n";

        for $adapter (@{$ipconfig->get_adapters}) {
            print "\nAdapter ";
            print $adapter->get_id, "\n";
            print $adapter->get_description, "\n";

            if ($adapter->is_dhcp_enabled) {
                print "DHCP is enabled\n";
            } else {
                print "DHCP is not enabled\n";
            }

            @ipaddresses = @{$adapter->get_ipaddresses};
            print "ipaddresses=@ipaddresses (", scalar @ipaddresses, ")\n";

            @gateways = @{$adapter->get_gateways};
            print "gateways=@gateways (", scalar @gateways, ")\n";

            print "domain=", $adapter->get_domain, "\n";

            @dns = @{$adapter->get_dns};
            print "dns=@dns (", scalar @dns, ")\n";

            @wins = @{$adapter->get_wins};
            print "wins=@wins (", scalar @wins, ")\n";
        }
    }

DESCRIPTION

Win32::IPConfig is a module for retrieving TCP/IP network settings from a Windows NT/2000 host machine. Specify the host and the module will retrieve and collate all the information from the specified machine's registry (using Win32::TieRegistry). For this module to retrieve information from a host machine, you must have read access to the registry on that machine.

CONSTRUCTOR

$ipconfig = Win32::IPConfig->new($host);

Creates a new Win32::IPConfig object. $host is passed directly to Win32::TieRegistry, and can be a computer name or an IP address.

METHODS

$ipconfig->get_hostname

Returns a string containing the DNS hostname of the machine.

$ipconfig->get_domain

Returns a string containing the domain name of the machine. In the case of a Windows 2000 machine (which can have connection-specific domain names), this is the primary domain name.

$ipconfig->get_nodetype

Returns the node type of the machine. Note that this is not always there. It will default to

    0x1 - B-node
$ipconfig->get_adapters

The real business of the module. Returns a reference to list of Win32::IPConfig::Adapter objects. See the following section for more information.

EXAMPLES

Collecting IP Settings for a list of PCs

    use Win32::IPConfig;

    print "hostname,domain,dhcp?,ipaddresses,gateways,dns servers,wins servers\n";
    while (<DATA>) {
        chomp;
        $ipconfig = Win32::IPConfig->new($_);
        print $ipconfig->get_hostname, ",", $ipconfig->get_domain, ",";
        if (@adapters = @{$ipconfig->get_adapters}) {
            $adapter = $adapters[0];
            if ($adapter->is_dhcp_enabled) {
                print "Y,";
            } else {
                print "N,";
            }
            @ipaddresses = @{$adapter->get_ipaddresses};
            print "@ipaddresses,";
            @gateways = @{$adapter->get_gateways};
            print "@gateways,";
            @dns = @{$adapter->get_dns};
            print "@dns,";
            @wins = @{$adapter->get_wins};
            print "@wins";
        }
        print "\n";
    }

    __DATA__
    HOST1
    HOST2
    HOST3

REGISTRY KEYS USED

IP configuration information is stored in a number of registry keys under HKLM\SYSTEM\CurrentControlSet\Services.

To access adapter-specific configuration information, you need the adapter id, which can be found by examining the list of installed network cards at HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards.

Note that in NT the adapter id will look like a service or driver, while in 2000 it will be a GUID.

There are some variations in where Windows NT and Windows 2000 store TCP/IP configuration data. This is shown in the following lists. Note that Windows 2000 sometimes stores data in the old location as well as the new 2000 adapter-specific location. In these cases, the module will read the data from the new registry location.

IP Address Information

    Value: IPAddress (REG_MULTI_SZ)
    NT:    <adapter>\Parameters\Tcpip
    2000:  <adapter>\Parameters\Tcpip
    2000:  Tcpip\Parameters\Interfaces\<adapter>

    Value: SubnetMask (REG_MULTI_SZ)
    NT:    <adapter>\Parameters\Tcpip
    2000:  <adapter>\Parameters\Tcpip
    2000:  Tcpip\Parameters\Interfaces\<adapter>

    Value: DefaultGateway (REG_MULTI_SZ)
    NT:    <adapter>\Parameters\Tcpip
    2000:  <adapter>\Parameters\Tcpip
    2000:  Tcpip\Parameters\Interfaces\<adapter>

    Value: EnableDHCP (REG_DWORD)
    NT:    <adapter>\Parameters\Tcpip
    2000:  <adapter>\Parameters\Tcpip
    2000:  Tcpip\Parameters\Interfaces\<adapter>

DNS Information

    Value: Hostname (REG_SZ)
    NT:    Tcpip\Parameters
    2000:  Tcpip\Parameters

    Value: NV Hostname (REG_SZ)
    2000:  Tcpip\Parameters

    Value: Domain (REG_SZ)
    NT:    Tcpip\Parameters
    2000:  Tcpip\Parameters (primary)
    2000:  Tcpip\Parameters\Interfaces\<adapter> (connection-specific)

    Value: NameServer (REG_SZ) (a space delimited list)
    NT:    Tcpip\Parameters
    2000:  Tcpip\Parameters (although it was blank; is it used?)
    2000:  Tcpip\Parameters\Interfaces\<adapter>

    Value: SearchList (REG_SZ) (space delimited on NT, comma delimited on 2000)
    NT:    Tcpip\Parameters
    2000:  Tcpip\Parameters

WINS Information

    Value: NameServer (REG_SZ)
    NT:    Netbt\Adapters\<adapter>

    Value: NameServerBackup (REG_SZ)
    NT:    Netbt\Adapters\<adapter>

    Value: NameServerList (REG_MULTI_SZ)
    2000:  Netbt\Parameters\Interfaces\Tcpip_<adapter>

Q120642 and Q314053 talk about NameServer and NameServerBackup existing on 2000 in the Netbt\Parameters\Interfaces\Tcpip_<adapter> registry key, but this appears to be wrong.

    Value: NodeType (REG_DWORD)
    NT:    Netbt\Parameters
    2000:  Netbt\Parameters

AUTHOR

James Macfarlane, <jmacfarla@cpan.org>

SEE ALSO

Win32::TieRegistry

The following Microsoft support articles were helpful:

  • Q120642 TCP/IP and NBT Configuration Parameters for Windows 2000 or Windows NT

  • Q314053 TCP/IP and NBT Configuration Parameters for Windows XP