本帖最后由 yakeyun 于 2022-2-19 16:53 编辑
回复 4# 窄口牛
如果主机存在多张网卡,多个MAC地址的,可以用下面代码先获取到当前联网的MAC信息,然后再修改为其MAC名称。
缺点是如果没有联网,就获取不到联网的网卡MAC值,无法修改。- @echo off&setlocal enabledelayedexpansion
- %1 mshta vbscript:CreateObject("Shell.Application").ShellExecute("cmd.exe","/c %~s0 ::","","runas",1)(window.close)&&exit
- set ons=TRUE
- for /f "tokens=* " %%a in ('wmic nic get macaddress ^,NetEnabled ^|find /i "%ons%"') do set netdata=%%a
- for /f "tokens=1-6 delims=:" %%b in ('echo %netdata% ^|find /i ":"') do set macdata=%%b-%%c-%%d-%%e-%%f-%%g
- for /f "tokens=1 delims=^ " %%m in ('echo %macdata%') do set pcname=%%m
- echo 当前联网网卡MAC为:%pcname%
- wmic computersystem where "name='%computername%'" call rename "%pcname%" >nul 2>nul
- echo,
- echo,
- echo 一键修改完成!需要重启后方可生效,重启请回车继续。
- echo,
- echo,
- pause>nul
- shutdown -r -t 0
- exit
复制代码
|