1. 打开 PowerShell ,执行 Set-ExecutionPolicy Unrestricted 2. 将下面代码生成文件,在文件点右键选择“使用 PowerShell 运行” 3. 在“输入命令:”提示中输入cycle 4. 再输入s 1 0102030a0b0c 说明 1 是指网上列表号 0102030a0b0c 是新设置的网卡MAC地址,由于Win7之后MAC会有很多限制,不是随便设置。如果不清楚就试多几组数字。 5. 输入 quit 退出 6. 在 PowerShell 执行 Set-ExecutionPolicy Restricted
文件: MAC地址修改.ps1 # # mcmkup.ps1 version 0.33 20110727 # Created by Marcello Gorlani # http://www.gorlani.com/portal/ # # You can freely use and distribute this junk as long you leave this credits # This software comes with no warranty. It may destroy life on the Earth as we know it. Be warned. # # 汉化: 1788469 # # 如果出现: 无法加载文件 MAC地址修改.ps1,因为在此系统中禁止执行脚本。有关详细信息,请参阅 "get-help about_signing"。 # 解决方法: 在PowerShell中执行 Set-ExecutionPolicy Unrestricted # 运行脚本后执行 Set-ExecutionPolicy Restricted 恢复禁止执行脚本 # #
$CLUTTER_STUFF="`nmcmkup.ps1 0.33 20110727 by Marcello Gorlani 汉化: 1788469`n"
# Me-big-hacker super-secret key and value. See http://technet.microsoft.com/en-us/library/cc780532(WS.10).aspx $REGKEY='HKLM:\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}' $VALUE_NAME='NetworkAddress'
$LOOKUP_REGKEY='HKLM:\SYSTEM\CurrentControlSet\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}'
# This will be used to identify physical NICs $NCF_PHYSICAL=4
# Various parsing parameters $CMD_MIN_LEN=3 $MIN_CMD_TOKS=1 $QUITCMD='quit'
# For minimal validity checks $GOOD_MAC_LEN=12
# Why bother about errors if you can hide them? $ErrorActionPreference="SilentlyContinue"
###################################################################### # Global variables # ######################################################################
# By default, we DO NOT powercycle the interface after spoofing. Set this to $true to have the opposite default [boolean] $global:bCycleInterface=$false
# Follow my lips: N-O [boolean] $global:bIdontKnowWhatImDoingAndWantFuckUpThings=$false
######################################################################
###################################################################### # Find the visible name of the interface # ###################################################################### function getNICDesc([string] $sCfgKey) { $refKey=$LOOKUP_REGKEY+'\'+$sCfgKey+'\Connection' $nicName=Get-ItemProperty $refKey -Name 'Name' return $nicName.Name }
###################################################################### # Build a list of physical interfaces # ###################################################################### function buildIntList([string] $sKey, [boolean] $bOnlyPhy=$True) { $fillMe=@() foreach ($subInt in Get-ChildItem -path $sKey | Get-ItemProperty -Name Characteristics,PSChildName,DriverDesc,NetWorkAddress,NetCfgInstanceId) { #$subInt.Characteristics #$subInt.PSChildName #$subInt.DriverDesc if ($subInt.Characteristics -bAND $NCF_PHYSICAL -or $global:bIdontKnowWhatImDoingAndWantFuckUpThings) { # We found a physical device $nicDesc=getNICDesc $subInt.NetCfgInstanceId $iDevID=[int32] $subInt.PSChildName $hElement=@{PSPath=$subInt.PSPath;DDesc=$subInt.DriverDesc;MAC=$subInt.NetWorkAddress;VisibleName=$nicDesc;DevID=$iDevID} $fillMe += $hElement } } return $fillMe }
###################################################################### # Write out the list of physical interfaces # ###################################################################### function dumpArray([System.Array] $dumpMe) { if ($dumpMe.Count -lt 1) { Write-Host 出错,不能找到网卡 return } Write-Host "`n下面是这台主机的物理网卡列表:`n" $iCount=0 foreach ($nic in $dumpMe) { if ($nic.MAC.Length -gt 0) { $sMac='MAC设置为: ' + $nic.MAC } else { $sMac='保持原MAC' } [String] $sLine=$iCount.Tostring() + ') ' + $nic.VisibleName +', [' + $nic.DDesc + '], ' + $sMac Write-Host $sLine $iCount++ } Write-Host "`n自动即时生效设置: $bCycleInterface`n" }
###################################################################### # Write help # ###################################################################### function dumpCommands() { Write-Host $CLUTTER_STUFF Write-Host '命令:' Write-Host 'c <网卡号>' Write-Host 's <网卡号> <新mac>' Write-Host 'cycle' Write-Host $QUITCMD Write-Host '' Write-Host '命令 c 清除 MAC地址 (恢复原MAC地址)' Write-HOst '命令 s 设置新 MAC地址' Write-HOst '命令 cycle 设置自动启动使设置即时生效' Write-Host '命令 quit 退出设置' Write-Host '' Write-HOst '示例:' Write-Host 'cycle' Write-HOst 'c 0 恢复 0 网卡的MAC' Write-HOst 's 1 0102030a0b0c 设置 1 网卡的MAC为 0102030a0b0c' Write-Host 'quit' Write-Host '' }
###################################################################### # Parse the input to figure out if we must do something # ###################################################################### function chkPowerCycle([int32] $iThisOne) { if ($global:bCycleInterface -eq $False) { return } Write-Host 搜索设备... $nicDevice=Get-WmiObject -Class win32_networkadapter | Where-Object {$_.DeviceId -eq $iThisOne } if ($nicDevice -ne $null) { Write-Host 禁用... $nicDevice.Disable() | Out-Null Write-Host 启用... $nicDevice.Enable() | Out-Null Write-Host Windows 承认的 MAC 地址是: $nicDevice.MACAddress } else { Write-Host 无法找到设备 $iThisOne } }
###################################################################### # Parse the input to figure out if we must do something # ###################################################################### function runThisCmd([String] $sCmd, [System.Array] $nicArray) { $toks=$sCmd.Trim().Split(' ') if ($toks.Count -lt $MIN_CMD_TOKS) { Write-Host '缺少参数' return } if ($toks[0] -ne 'c' -and $toks[0] -ne 's' -and $toks[0] -ne 'cycle') { Write-Host '无效命令: ' $toks[0] dumpCommands return } [int32]$iArID=$toks[1] if ($iArID -lt 0 -or $iArID -gt $nicArray.count) { Write-Host 无效网卡号 $iArId return } $keyToModify=$nicArray[$iArId].PSPath switch ($toks) { 's' { setMAC $keyToModify $sCmd chkPowerCycle $nicArray[$iArId].DevID } 'c' { clearMAC $keyToModify chkPowerCycle $nicArray[$iArId].DevID } 'cycle' { $global:bCycleInterface= -not $global:bCycleInterface } } }
###################################################################### # Set the new MAC address # ###################################################################### function setMAC([System.Object] $theKey, [string] $cmd) { $toks=$cmd.Trim().Split(' ') if ($toks.Count -ne 3) { Write-Host 命令参数无效 return } [string]$sNewMac=$toks[2] if ($sNewMac.Length -ne $GOOD_MAC_LEN) { Write-Host 无效MAC $sNewMac return } Write-Host 设置... Set-ItemProperty $theKey -Name $VALUE_NAME -Value $sNewMac Write-Host 新的MAC地址已设置. 禁用网卡后再启用. }
###################################################################### # Revert to original MAC # ###################################################################### function clearMAC([System.Object] $theKey) { Write-Host 恢复... Clear-ItemProperty $theKey -Name $VALUE_NAME Write-Host 恢复原MAC地址. 禁用网卡后再启用. }
###################################################################### # Entry point # ######################################################################
Clear dumpCommands while ($true) { $command=''
# Figure out which interfaces we have and put it in an array of hash tables $intList=buildIntList $REGKEY $true # Give some hint #dumpCommands # List the NICs we found dumpArray $intList
# Read commands from the user while ($command.Length -lt $CMD_MIN_LEN) { $command=read-Host '输入命令' }
if ($command -ne $QUITCMD) { runThisCmd $command $intList } else { break } } # Main Loop
Write-Out Bye
### DO NOT MODIFY BEYOND THIS LINE ### 网址: http://www.gorlani.com/portal/projects/macmakeup-for-vista-seven-2008-windows-8
|