Renew DHCP lease for all adapters made by Intel (Perl)
This code can be found in
Chapter 12 of Windows XP Cookbook
Purchase XP Cookbook or Networking Recipes for only $25 plus shipping! While supplies last.
Find out how to download all of the Perl code from this site.
# From the book "Windows XP Cookbook"
# ISBN: 0596007256
# ------ SCRIPT CONFIGURATION ------
use Win32::OLE qw(in);
$strComputer = '.';
# ------ END CONFIGURATION ---------
$objWMI = Win32::OLE->GetObject('winmgmts:\\\\' . $strComputer . '\\root\\cimv2');
$colNAs = $objWMI->ExecQuery('select * ' . ' from Win32_NetworkAdapter ' . ' where manufacturer = \'Intel\' ');
foreach my $objNA (in $colNAs) {
$colSubNAConfig = $objWMI->ExecQuery('ASSOCIATORS OF {Win32_NetworkAdapter.DeviceID=\'' . $objNA->DeviceID . '\'} ' . ' WHERE resultClass = win32_NetworkAdapterConfiguration ');
foreach my $objNAConfig (in $colSubNAConfig) {
if ($objNAConfig->DHCPEnabled == 1) {
$intRC = $objNAConfig->RenewDHCPLease();
if ($intRC == 0) {
print 'Renewed IP address for ' . $objNA->Name, "\n";
}
elsif ($intRC == 1) {
print 'You must reboot to renew the IP address for ' . $objNA->Name, "\n";
}
else {
print 'There was an error renewing the IP address for ' . $objNA->Name . ': ' . $intRC, "\n";
}
}
}
}
|
This code has been viewed 1225 times.
|
New from the creators of TechTasks.com:
StatSheet.com
|