请“iawn1989”看下是不是可以
1。跟根据虚拟网卡在注册表的ComponentId或者是DriverDesc网卡名称。(补充一下,如果用批处理无法做到确定那张是虚拟网卡的情况下,可以扫描DriverDesc,然后列说本计算机所有的网卡,手动选择.1或者2)
2。如果递加难做得到比较易懂完善的,也可以参考读取文本mac的办法,读取一个IP [macip.txt 格式005056d00012=192.168.1.4]
3。不考虑decvon,需要重起
使用方法 test 255.255.255.0 192.168.1.2- rem 下面是test.bat内容
- @echo off
- set mask=%1
- set gw=%2
- echo 正在读取网卡信息......
- for /f "delims=:" %%i in ('findstr /n . macip.txt') do set total=%%i
- set /a rnd=%random% %% %total%
- if %rnd% equ 0 set rnd=1
- for /f "tokens=1* delims=:" %%i in ('findstr /n .* macip.txt') do (if %%i equ %rnd% set macad=%%j)
- for /f "tokens=1,2 delims==" %%j in ("%macad%") do set mac=%%j&&set ip=%%k
-
- cd.>2.txt&cd.>s.txt
- regedit /e a.reg HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}
- for /f "tokens=1,4 delims=," %%a in ('getmac /v /fo:csv /nh') do >>s.txt set/p=%%a<nul&>>s.txt set/p=";"<nul&for /f "tokens=2
-
- delims={" %%o in (%%b) do echo %%o>>s.txt
- findstr /n .* s.txt >3.txt
- for /f "delims=:" %%b in ('type a.reg ^| findstr /n ^[') do echo %%b>>2.txt
-
- echo .
- echo -----------------
- for /f "delims=;" %%a in (3.txt) do echo %%a
- echo -----------------
- SET Choice=
- SET /P Choice= 请选择网卡:
- for /f "tokens=1,2 delims=;" %%a in ('findstr "^%Choice%" 3.txt') do set kk=%%b&&for /f "tokens=2 delims=:" %%z in ("%%a") do
-
- set nicid=%%z
-
- :Getkey _key
- echo 正在 查找 注册表......
- for /f "tokens=1* delims=:" %%i in ('type a.reg ^| findstr /n %kk%') do (set ok=%%i)
- setlocal enabledelayedexpansion
- for /f %%k in (2.txt) do ( set /a dif=%%k-%ok% & if !dif! leq 0 set li=%%k)
- for /f "tokens=1* delims=:" %%i in ('type a.reg ^| findstr /n .*') do (if %%i equ !li! call :Makereg %%j)
- endlocal
- goto :eof
-
- :Makereg
- echo Windows Registry Editor Version 5.00 >changemac.reg
- echo.>>changemac.reg
- echo %1 >>changemac.reg
- echo "NetworkAddress"="%mac%">>changemac.reg
- echo 正在 设置 %nicid% 的MAC地址......
- reg import changemac.reg 1>nul
- if %errorlevel% equ 0 (echo [%nicid% MAC地址设置为 %mac%] 处理完成) else (echo [ MAC地址设置 失败 ]&goto :end)
- echo 正在 设置 %nicid% 的IP地址......
- netsh interface ip set address "%nicid%" static %ip% %mask% %gw% 1 >nul
- if %errorlevel% equ 0 (echo [%nicid% IP地址设置为 %ip%] 处理完成) else (echo [ IP地址设置 失败 ])
- goto :end
-
- :end
- del 2.txt&del 3.txt&del s.txt&del a.reg&del changemac.reg
复制代码
[ 本帖最后由 shihao 于 2010-11-10 09:55 编辑 ] |