
楼上朋友说的基本不错
只是win7下
那些名字改成中文就行
@echo
off
for
/f
"tokens=2
delims=:"
%%i
in
('ipconfig
/all^|findstr
/i
/c:"ipv4
地址"')
do
(set
a=ip:%%i)
for
/f
"tokens=2
delims=:"
%%i
in
('ipconfig
/all^|findstr
/i
/c:"物理地址"')
do
(set
b=mac:%%i)
echo
%a%
echo
%b%
pause
@echo off
for /f "tokens=2 delims=:" %%a in ('ipconfig /all^|find "Physical Address"') do set MAC=%%a
echo ╭—————————————————╮
echo │ 本机MAC地址:%MAC: =% │
echo ╰—————————————————╯
set /p MAC=请输入MAC地址(十六进制):
echo %MAC%|findstr "^[0-9a-fA-F]$">nul||cls&&echo 你输入的不是16进制MAC地址!&&echo 请重新输入&&goto MACset
for /l %%i in (0,1,1000) do if "!MAC:~%%i,1!"=="" set strlen=%%i&&goto pass
:pass
if %strlen% GTR 12 (cls&&echo 你输入的MAC地址位数大于12位&&echo 程序自动截取前12位,设定如下:) else (if %strlen% LSS 12
(cls&&echo 你输入的MAC地址位数小于12位&&echo 请重新输入!&&goto MACset) else (if %strlen% EQU 12 cls&&echo 输入MAC地址位数
正确))
echo ╭—————————————————╮
echo │输入的MAC为:%MAC:~0,2%-%MAC:~2,2%-%MAC:~4,2%-%MAC:~6,2%-%MAC:~8,2%-%MAC:~10,2% │
echo ╰—————————————————╯
set MAC=%MAC:~0,12%
echo ╭—————————————————╮
echo │正 在 修 改 本 机 MAC 地 址…… │
echo ╰—————————————————╯
@reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}\0008" /v
NetworkAddress /t reg_SZ /d %MAC% /f>nul
::获取本地连接名
for /f "tokens=2, delims= " %%a in ('ipconfig /all^|find "Ethernet adapter"') do set hj=%%b
set ipname=%hj::=%
::自动断线重连,启用新的MAC地址
echo Const ssfCONTROLS = 3 >"%temp%\00vbs"
echo sConnectionName = "%ipname%" '可改成需要控制的连接名称,如"无线网络连接"、"区域联机 2"等>>"%temp%\00vbs"
echo sEnableVerb = "启用(&A)">>"%temp%\00vbs"
echo sDisableVerb = "停用(&B)">>"%temp%\00vbs"
echo >>"%temp%\00vbs"
echo set wmi = GetObject("winmgmts:")>>"%temp%\00vbs"
echo set colSystem = wmiExecQuery("select from Win32_OperatingSystem")>>"%temp%\00vbs"
echo for each objSystem in colSystem>>"%temp%\00vbs"
echo if Instr(UCase(objSystemCaption),UCase("Windows XP")) then '如果系统是WinXP>>"%temp%\00vbs"
echo sNetConnections = "网络连接">>"%temp%\00vbs"
echo sDisableVerb = "停用(&B)">>"%temp%\00vbs"
echo else '如果系统是Win2000>>"%temp%\00vbs"
echo sNetConnections = "网络和拨号连接">>"%temp%\00vbs"
echo sDisableVerb = "禁用(&B)">>"%temp%\00vbs"
echo end if>>"%temp%\00vbs"
echo next>>"%temp%\00vbs"
echo >>"%temp%\00vbs"
echo set shellApp = createobject("shellapplication")>>"%temp%\00vbs"
echo set oControlPanel = shellAppNamespace(ssfCONTROLS)>>"%temp%\00vbs"
echo >>"%temp%\00vbs"
echo set oNetConnections = nothing>>"%temp%\00vbs"
echo for each folderitem in oControlPanelitems>>"%temp%\00vbs"
echo if folderitemname = sNetConnections then>>"%temp%\00vbs"
echo set oNetConnections = folderitemgetfolder>>"%temp%\00vbs"
echo exit for>>"%temp%\00vbs"
echo end if>>"%temp%\00vbs"
echo next>>"%temp%\00vbs"
echo >>"%temp%\00vbs"
echo if oNetConnections is nothing then>>"%temp%\00vbs"
echo WScriptEcho "控制面板中未找到" ^& sNetConnections ^& "活页夹">>"%temp%\00vbs"
echo wscriptquit>>"%temp%\00vbs"
echo end if>>"%temp%\00vbs"
echo >>"%temp%\00vbs"
echo set oLanConnection = nothing>>"%temp%\00vbs"
echo for each folderitem in oNetConnectionsitems>>"%temp%\00vbs"
echo 'WScriptEcho folderitemname>>"%temp%\00vbs"
echo if lcase(folderitemname) = lcase(sConnectionName) then>>"%temp%\00vbs"
echo set oLanConnection = folderitem>>"%temp%\00vbs"
echo exit for>>"%temp%\00vbs"
echo end if>>"%temp%\00vbs"
echo next>>"%temp%\00vbs"
echo >>"%temp%\00vbs"
echo if oLanConnection is nothing then>>"%temp%\00vbs"
echo WScriptEcho sNetConnections ^& "中未找到'" ^& sConnectionName ^& "'项目">>"%temp%\00vbs"
echo wscriptQuit>>"%temp%\00vbs"
echo end if>>"%temp%\00vbs"
echo >>"%temp%\00vbs"
echo bEnabled = true>>"%temp%\00vbs"
echo set oEnableVerb = nothing>>"%temp%\00vbs"
echo set oDisableVerb = nothing>>"%temp%\00vbs"
echo s = "Verbs: " ^& vbcrlf>>"%temp%\00vbs"
echo for each verb in oLanConnectionverbs>>"%temp%\00vbs"
echo 'WScriptEcho verbname>>"%temp%\00vbs"
echo 's = s ^& vbcrlf ^& verbname>>"%temp%\00vbs"
echo if verbname = sEnableVerb then>>"%temp%\00vbs"
echo set oEnableVerb = verb>>"%temp%\00vbs"
echo bEnabled = false>>"%temp%\00vbs"
echo end if>>"%temp%\00vbs"
echo if verbname = sDisableVerb then>>"%temp%\00vbs"
echo set oDisableVerb = verb>>"%temp%\00vbs"
echo end if>>"%temp%\00vbs"
echo next>>"%temp%\00vbs"
echo >>"%temp%\00vbs"
echo 'debugging displays left just in case>>"%temp%\00vbs"
echo '>>"%temp%\00vbs"
echo 'msgbox s ': wscriptquit>>"%temp%\00vbs"
echo 'msgbox "Enabled: " ^& bEnabled ': wscriptquit>>"%temp%\00vbs"
echo >>"%temp%\00vbs"
echo 'not sure why, but invokeverb always seemed to work>>"%temp%\00vbs"
echo 'for enable but not disable>>"%temp%\00vbs"
echo '>>"%temp%\00vbs"
echo 'saving a reference to the appropriate verb object>>"%temp%\00vbs"
echo 'and calling the DoIt method always seems to work>>"%temp%\00vbs"
echo '>>"%temp%\00vbs"
echo if bEnabled then>>"%temp%\00vbs"
echo ' oLanConnectioninvokeverb sDisableVerb>>"%temp%\00vbs"
echo 'if msgbox(sConnectionName ^& " 当前状态:已启用", 36, "是否停用")=vbYes then>>"%temp%\00vbs"
echo oDisableVerbDoIt>>"%temp%\00vbs"
echo 'then>>"%temp%\00vbs"
echo else>>"%temp%\00vbs"
echo ' oLanConnectioninvokeverb sEnableVerb>>"%temp%\00vbs"
echo 'if msgbox(sConnectionName ^& " 当前状态:已禁用", 36, "是否启用")=vbYes then>>"%temp%\00vbs"
echo oEnableVerbDoIt>>"%temp%\00vbs"
echo 'then>>"%temp%\00vbs"
echo end if>>"%temp%\00vbs"
echo >>"%temp%\00vbs"
echo 'adjust the sleep duration below as needed>>"%temp%\00vbs"
echo '>>"%temp%\00vbs"
echo 'if you let the oLanConnection go out of scope>>"%temp%\00vbs"
echo 'and be destroyed too soon, the action of the verb>>"%temp%\00vbs"
echo 'may not take>>"%temp%\00vbs"
echo '>>"%temp%\00vbs"
echo wscriptsleep 1000>>"%temp%\00vbs"
echo >>"%temp%\00vbs"
echo set oNetConnections = nothing>>"%temp%\00vbs"
echo set oLanConnection = nothing>>"%temp%\00vbs"
echo set oEnableVerb = nothing>>"%temp%\00vbs"
echo set oDisableVerb = nothing>>"%temp%\00vbs"
echo >>"%temp%\00vbs"
call "%temp%\00vbs"
echo Wscriptsleep 5000>"%temp%\5vbs"&&call "%temp%\5vbs"&&del "%temp%\5vbs" /q
call "%temp%\00vbs"&&del "%temp%\00vbs"
cls
echo ╭—————————————————╮
echo │ 修 改 本 机 MAC 地 址 完 成 │
echo ╰—————————————————╯
先给你这一段,关于你要的实现一个文件里多个MAC地址的变更,联系我,我再帮你修改!
1、
@echo off
for /f "tokens=12 delims= " %%i in ('ipconfig/all^|find /i "phys"')do if not defined m set "m=%%i"
if not exist c:\123\ md c:\123
echo %m%>c:\123\atxt
2、
@echo off
for /f "tokens=12 delims= " %%i in ('ipconfig/all^|find /i "phys"')do if not defined m set "m=%%i"
find /i "%m%" c:\123\atxt &&start "" 1exe||start "" 2exe
可以的,请测试!
getmac >>d:\mactxt
rem 将本机mac地址输出到d盘mactxt文档
rem 系统自带的工具getmac:此工具使管理员能够显示系统上网络适配器的 MAC 地址
那建议你还是试试用VB来写吧。批处理获取IP基本上就是IPCONFIG指令,从里面把IP地址分离出来并不简单。获取MAC地址有个GETMAC命令,但好像不是每个 *** 作系统都支持,我只在Windows 81上测试过。
楼主第2问我没看懂,下面给出代码,如果不是楼主想要的,就HI我吧。
@echo off
setlocal enabledelayedexpansion
for /f "tokens=1-2 delims=:" %%i in ('ipconfig /all ^|findstr "Physical Address"') do (
set jieguo=%%j
echo !jieguo!|find "-" && goto next
)
:next
set mac=!jieguo:-=!
echo 123>>1txt
echo 我的MAC地址为:%mac: =%>>1txt
exit
BAT-GO百度知道团队--xie3331
这样吧,把我原来的弄的说一下,制作了一个批处理,它会在需要改文件处生成一个新批处理,并在开机启动项里多个启动项,就是调用这新批处理的,而这批处理执行又会删除这个启动项,也就是说,利用网络传的系统,当每台机重启一次就把proe按各自的mac弄好了,但是你的实际情况不一定和我一模一样,就只把用批处理会生成的批处理代码贴给你,并删去了处理启动项的代码。我是把原要处理的文件它是licdat提前复制了一份取名为lic0txt的,并且把它原来自带的批处理合到一起了,那个批处理就是一句 ptcrypt -i licdat -o licensedat 如果你的不是这样的,自己酌情处理,不要这句已可以完成替换,但是可能还得自己去运行它的生成授权文件的程序
@echo off
set mac0=11-22-33-44-55-66
setlocal enabledelayedexpansion
cd/d "%~dp0"
copy/y lic0txt lic
for /f "tokens=3 delims=: " %%i in ('ipconfig/all^|find "Physical"')do set mac=%%i&goto :next
:next
(for /f "delims=" %%j in (lic)do (
set hs=%%j
set hs=!hs:%mac0%=%mac%!
echo!hs!))>licdat
del lic
ptcrypt -i licdat -o licensedat
echo OK
ping -n 3 1271>nul
@echo off
For /f "delims=: tokens=2" %%i in ('ipconfig /all ^|find /i "Physical" ') do echo Mac地址为:%%i & goto end
:end
pause
以上就是关于批处理获取MAC和IP的问题全部的内容,包括:批处理获取MAC和IP的问题、我想用vbs或者批处理实现获取本机的mac地址,然后修改一个文件里面的多个mac地址为本机的mac地址、bat--批处理---获取计算机物理MAC信息--等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)