是否有某些 MAC 地址供应商代码在 windows 上不起作用,或者我的代码是否有其他问题?

Are there certain MAC address vendor codes that don't work on windows or is there something else wrong with my code?

跟随@Asian 的 以及我最近对 ​​powershell 的兴趣,我尝试复制我提供的脚本来回答 Asian 的问题,但是我没有像使用批处理脚本那样成功。如果您不想查看上一个问题,这是我用于更改您的 MAC 地址的批处理文件:

@echo off
dism >nul
if %errorlevel% NEQ 0 goto Elevate
(call )
netsh interface set interface Wi-Fi disable
timeout /t 1 /nobreak >null
netsh interface set interface Wi-Fi enable
choice /c RC /m "Would you like to randomize your MAC adress or customize it?"
if %Errorlevel% EQU 2 goto custom
set loopcount=5
:loop
set /a loopcount=loopcount-1
if %loopcount% LEQ 0 (goto exitloop)
set /a "ascii = %random% * 26 / 32768 + 65"
cmd /c exit /b %ascii%
set "rl1=%rl1%%=ExitCodeAscii%"
goto loop
:exitloop
set MAC="0E%random:~0,2%%rl1:~0,2%%random:~0,2%%rl1:~3,2%%rl1:~-1%%random:~0,1%"
goto after
:custom
echo What would you like to change your MAC address to?
echo Remember to always have the second digit of your MAC address to always be a 2, 6, A, or E
echo Format: AABBCCDDEEFF
echo/
set /p MAC="Input your MAC address here (no spaces or hyphens)> "
:after
reg add "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Class\{4d36e972-e325-11ce-bfc1-08002be10318}[=12=]11" /v NetworkAddress /d %MAC% /f >null
netsh interface set interface Wi-Fi disable
timeout /t 1 /nobreak >null
netsh interface set interface Wi-Fi enable
echo Operation Successful
echo %mac% is your new MAC address
pause
goto :eof
:Elevate
Echo Error: The requested operation requires elevation
Echo Run file again as admin
Echo Closing file in 10 seconds...
timeout /t 10 /nobreak >nul
goto :eof

我试图在 powershell 中复制它,但是脚本是否有效非常不稳定:

[string]$admin = [bool](([System.Security.Principal.WindowsIdentity]::GetCurrent()).groups -match "S-1-5-32-544")
if ($admin -eq "False"){
echo "Error: The requested operation requires elevation`nRun file again as administrator"
pause
exit}
rv * -ErrorAction SilentlyContinue
echo "This file will temporarily disable your Wi-Fi adapter"
While (!($C1)){
$choice1 = Read-Host -Prompt "Would you like to proceed? [Y/N]"
switch ($choice1) {
   "N" {echo "Ok, press any key to exit this file:"
        cmd /c pause > $null; exit}
   "Y" {echo "Ok, proceeding with operation"; [int]$C1 = 1; break}
   }
if (!($C1)){echo "Invalid input"}
}
rv * -ErrorAction SilentlyContinue

netsh interface set interface Wi-Fi disable; 

$getwifi = netsh interface show interface | findstr "Wi-Fi"
if ($getwifi.substring(0,7) -ne "disable"){echo "Unexpected error: Press any key to exit"
                                           cmd /c pause > $null; exit}
echo "Wi-Fi has been succesfully disabled, proceeding with operation"

While (!($C1)){
    $choice1 = Read-Host -Prompt "Would you like to randomize your MAC Address or customize it? [R/C]"
    switch ($choice1) {
        "R" {
            $test = @(...) | get-random
            <# $test is a random value in a list of 25000+ MAC Address vendor codes provided in 
            https://gitlab.com/wireshark/wireshark/raw/master/manuf with the colons removed and columns 
            besides the MAC column removed as well #>
            $test2 = [string](get-random -minimum 10 -maximum 99)+(-join ((65..90) | Get-Random -Count 2 | % {[char]$_}));
            $test3 = [string](get-random -minimum 1 -maximum 9)+(-join ((65..90) | Get-Random -Count 1 | % {[char]$_}));
            $MAC = $test + $test2 + $test3;
            $C1 = 1}
        "C" {$C1 = 2}
    }
if (!($C1)){echo "Invalid input"}
}

if(!($MAC)){
do{
echo "What would you like to change your MAC address to?`nRemember to always have the second digit of your MAC address to always be a number`nFormat: 11BBCCDDEEFF";
$MAC = read-host -prompt "Input your MAC address here [no spaces or hyphens]";
if ($MAC.length -eq 12){$C1 = 1};
if (!($MAC.length -eq 12)){echo "Invalid input: Follow the format"; rv MAC}
} while(!($MAC))
}
reg add "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Class\{4d36e972-e325-11ce-bfc1-08002be10318}[=13=]11" /v NetworkAddress /d $MAC /f >$null
netsh interface set interface Wi-Fi enable
echo "Operation Successful"
echo "$MAC is your new MAC address"
pause

同样,$test 是 https://gitlab.com/wireshark/wireshark/raw/master/manuf 中提供的 25000+ MAC 地址供应商代码列表中的一个随机值,其中冒号被删除,MAC 列之外的列被删除为出色地。我认为问题出在 $test 变量中,计算机只会拒绝某个 MAC 地址。如果这不是问题,有人可以向我解释问题是什么吗,如果有某些代码始终可以成功更改 MAC 地址,请提供给我。提前谢谢你。

一些有用的地址包括:

我测试的时候会把更多的示例地址写下来

尝试macaddr=$(echo $FQDN|md5sum|sed 's/^\(..\)\(..\)\(..\)\(..\)\(..\).*$/02:::::/') &> /dev/null && echo macaddr。这将生成一个随机 MAC 地址并将其回显给您。不过,这仅适用于 Ubuntu/Bash。

您也可以在 PowerShell 中执行 (1..12 | %{ '{0:X}' -f (Get-Random -Max 16) }) -join ''