簡體   English   中英

是否有某些 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 的興趣之后,我嘗試復制我提供的腳本來回答亞洲人的問題,但是我沒有像使用批處理腳本那樣成功。 如果您不想查看上一個問題,這是我更改 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}\0011" /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}\0011" /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 地址,請提供給我。 先感謝您。

一些有效的地址包括:

  • AABBCCDDEEFF
  • 001122334455
  • 00AA11BB22CC
  • 00的其他變種----------
  • 6E80F12CC8C9

當我測試它們時,我會寫下更多的示例地址。

試試macaddr=$(echo $FQDN|md5sum|sed 's/^\(..\)\(..\)\(..\)\(..\)\(..\).*$/02:\1:\2:\3:\4:\5/') &> /dev/null && echo macaddr 這將生成一個隨機 MAC 地址並將其回顯給您。 不過,這只適用於 Ubuntu/Bash。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM