The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Win32::IPConfig::Adapter - Network Adapter IP Configuration Settings for Windows NT/2000/XP/2003

SYNOPSIS

    use Win32::IPConfig;

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

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

        my @searchlist = $ipconfig->get_searchlist;
        print "searchlist=@searchlist (", scalar @searchlist, ")\n";

        print "nodetype=", $ipconfig->get_nodetype, "\n";

        print "IP routing enabled=", $ipconfig->is_router ? "Yes" : "No", "\n";

        print "WINS proxy enabled=",
            $ipconfig->is_wins_proxy ? "Yes" : "No", "\n";

        print "LMHOSTS enabled=",
            $ipconfig->is_lmhosts_enabled ? "Yes" : "No", "\n";

        print "DNS enabled for netbt=",
            $ipconfig->is_dns_enabled_for_netbt ? "Yes" : "No", "\n"; 

        foreach $adapter ($ipconfig->get_adapters) {
            print "\nAdapter '", $adapter->get_name, "':\n";

            print "Description=", $adapter->get_description, "\n";

            print "DHCP enabled=",
                $adapter->is_dhcp_enabled ? "Yes" : "No", "\n";

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

            @subnet_masks = $adapter->get_subnet_masks;
            print "subnet masks=@subnet_masks (", scalar @subnet_masks, ")\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::Adapter encapsulates the TCP/IP configuration settings for a Windows NT/2000/XP/2003 network adapter.

METHODS

$adapter->get_name

On Windows 2000 and later, returns the name of the connection as it appears in Network Connections, e.g. "Local Area Connection". On Windows NT returns the service name of the adapter (the same value as get_id).

$adapter->get_id

Returns the adapter id. This is used to determine where the adapter settings are stored. See REGISTRY KEYS USED in the Win32::IPConfig documentation.

$adapter->get_description

Returns the Network Adapter Description.

$adapter->is_dhcp_enabled

Returns 1 if DHCP is enabled, 0 otherwise. If DHCP is enabled, the values returned from the get_ipaddresses, get_gateways, get_domain, get_dns, and get_wins methods will be retrieved from the DHCP-specific registry keys.

$adapter->get_ipaddresses

Returns a list of IP addresses for this adapter. (Returns a reference to a list in a scalar context.)

$adapter->get_subnet_masks

Returns a list of subnet masks for this adapter. (Returns a reference to a list in a scalar context.) The order of subnet masks follows the order of IP addresses, so, for example, the 2nd subnet mask will match the 2nd IP address.

$adapter->get_gateways

Returns a list containing the default gateway IP addresses. (Returns a reference to a list in a scalar context.) If no default gateways are configured, an empty list will be returned. Statically configured default gateways will override any assigned by DHCP.

(Bet you didn't realise Windows allowed you to have multiple default gateways.)

$adapter->get_domain

Returns the connection-specific domain name suffix. A statically configured domain name suffix will override any assigned by DHCP.

Connection-specific domain name suffixes were introduced on Windows 2000. Windows NT machines do not support connection-specific domain names, so when run on Windows NT this method will return the domain name suffix for the host: all adapters on a Windows NT machine will therefore return the same domain name.

$adapter->get_dns

Returns a list containing DNS server IP addresses. (Returns a reference to a list in a scalar context.) If no DNS servers are configured, an empty list will be returned. Statically configured DNS Servers will override any assigned by DHCP.

Only Windows 2000 and later have DNS servers configured per adapter. Windows NT machines store the DNS servers as a property of the host, not of the adapter, so when run on Windows NT this method will return the DNS servers set for the host: all adapters on a Windows NT machine will therefore return the same DNS servers.

$adapter->get_wins

Returns a list containing WINS server IP addresses. (Returns a reference to a list in a scalar context.) If no WINS servers are configured, an empty list will be returned. Statically configured WINS Servers will override any assigned by DHCP.

$adapter->get_dhcp_server

Returns the IP address of the DHCP server that supplied the adapter's IP address.

You will only be able to read this value if the host adapter is configured through DHCP.

$adapter->get_dhcp_lease_obtained_time

Returns the time the DHCP lease began in the format YYYY-MM-DD HH-MM.

You will only be able to read this value if the host adapter is configured through DHCP.

$adapter->get_dhcp_lease_terminates_time

Returns the time the DHCP lease runs out in the format YYYY-MM-DD HH-MM.

You will only be able to read this value if the host adapter is configured through DHCP.

$adapter->set_domain($domain_suffix)

On Windows 2000 and later, sets the connection-specific domain name suffix. On Windows NT, sets the host-specific domain name suffix.

You will not be allowed to set this value if the host adapter is configured through DHCP.

When tested on a Windows NT system, the setting appeared to take effect immediately. When tested on a Windows 2000 system, the setting did not appear to take effect until the DNS Client service was restarted or the machine was rebooted.

$adapter->set_dns(@dns_servers)

Sets the DNS servers to @dns_servers. You can use an empty list to remove all configured DNS servers. On Windows 2000 and later, sets the DNS servers for the adapter; on Windows NT, sets the DNS servers for the host.

You will not be allowed to set this value if the host adapter is configured through DHCP.

When tested on a Windows NT system, the machine needed to be rebooted for it to take effect. When tested on a Windows 2000 system, the DNS Client service needed to be restarted or the machine rebooted.

$adapter->set_wins(@wins_servers)

Set the host's WINS servers to @wins_servers, which should be a list of contactable WINS servers on the network. You can use an empty list to remove all configured WINS servers. On Windows NT only the first two WINS servers will actually be set; on Windows 2000 and later, all the WINS servers you specify will be be inserted into the registry.

You will not be allowed to set this value if the host adapter is configured through DHCP.

When tested on a Windows NT system, the machine needed to be rebooted for the change to take effect. When tested on a Windows 2000 system, the machine also needed to be rebooted.

AUTHOR

James Macfarlane, <jmacfarla@cpan.org>

SEE ALSO

Win32::IPConfig