Release ip (Perl)

This code can be found in Chapter 10 of Windows Server 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.

# This code releases all DHCP IP addresses.

# ---------------------------------------------------------------
# Adapted from VBScript code contained in the book:
#      "Windows Server Cookbook" by Robbie Allen
# ISBN: 0-596-00633-0
# ---------------------------------------------------------------

use Win32::OLE;
$Win32::OLE::Warn = 3;

# ------ SCRIPT CONFIGURATION ------
$strComputer = '.';
# ------ END CONFIGURATION ---------
$objWMI = Win32::OLE->GetObject('winmgmts:\\\\' . $strComputer . '\\root\\cimv2');
$objAdapterConfig = $objWMI->Get('Win32_NetworkAdapterConfiguration');
$intRC = $objAdapterConfig->ReleaseDHCPLeaseAll();
if ($intRC == 0) {
    print "Released all DHCP IP addresses\n";
}
elsif ($intRC == 1) {
    print "You must reboot to release all DHCP IP addresses\n";
}
else {
    print 'There was an error releasing all DHCP IP addresses: ' . $intRC, "\n";
}

This code has been viewed 786 times.

New from the creators of TechTasks.com: StatSheet.com