# Kod konfiguruje dla okrelonego poczenia adres IP, mask podsieci i domyln bram

use Win32::OLE qw(in);
$Win32::OLE::Warn = 3;

# ------ SKONFIGURACJA SKRYPTU ------
$strComputer = '.';
$strConnection = 'Poczenie lokalne';
$strIP = ['1.22.2.2'];
$strMask = ['255.255.255.0'];
$strGatewayIP = ['1.2.3.3'];
# ------ KONIEC KONFIGURACJI ---------
$objWMI = Win32::OLE->GetObject('winmgmts:\\\\' . $strComputer . '\\root\\cimv2');
$colNA = $objWMI->ExecQuery('select * ' . ' from Win32_NetworkAdapter ' . ' where NetConnectionID = \'' . $strConnection . '\'');
foreach my $objNA (in $colNA) {
    $colNAConfig = $objWMI->ExecQuery('ASSOCIATORS OF {Win32_NetworkAdapter.DeviceID=\'' . $objNA->DeviceID . '\'} ' . ' WHERE resultClass = win32_NetworkAdapterConfiguration ');
    foreach my $objNAConfig (in $colNAConfig) {
        $intRC = $objNAConfig->EnableStatic($strIP, $strMask);
        $intRC2 = $objNAConfig->SetGateways($strGatewayIP);
        if ($intRC == 0 && $intRC2 == 0) {
            print "Adres IP skonfigurowano dla $strConnection\n";
        }
        elsif ($intRC == 1 || $intRC2 == 1) {
            print "Konieczne jest przeadowanie systemu, aby dokonane zmiany uwzgldniono dla $strConnection\n";
        }
        else {
            print 'Wystpi bd podczas konfigurowania adresu IP dla ' . $strConnection . ': ' . $intRC . ' and ' . $intRC2, "\n";
        }
    }
}
