- 帖子
- 22
- 积分
- 184
- 技术
- 0
- 捐助
- 0
- 注册时间
- 2009-4-24
|
哈,我刚刚在虚拟机里也是遇到了类似的问题,做的好一点应该做个清除现有配置(刚刚测试的时候产生的配置)项的功能,你==
下面的内容你保存一下(可以自动获取IP,也可以手动指定)
@echo off
:choice_A
echo ┌────────┐
echo │ [1] 手动指定ip │
echo │ [2] 自动获取ip │
echo │ 请选择... │
echo └────────┘
set /p choice_A=
if /i "%choice_A%"=="1" goto :choice_go1
if /i "%choice_A%"=="2" goto :choice_go2
goto choice_cc
netsh int ip set address name="本地连接" dhcp
:choice_go1
:::读取本机Mac地址
if exist ipconfig.txt del ipconfig.txt
ipconfig /all >ipconfig.txt
:::::::::读取本机ip地址
if exist IPAddr.txt del IPaddr.txt
find "IP Address" ipconfig.txt >IPAddr.txt
find "Subnet Mask" ipconfig.txt >MASKAddr.txt
for /f "skip=2 tokens=15" %%I in (IPAddr.txt) do set IP=%%I
for /f "skip=2 tokens=15" %%m in (MASKAddr.txt) do set MASKS=%%m
:::::::::读取网关地址
if exist GateIP.txt del GateIP.txt
find "Default Gateway" ipconfig.txt >GateIP.txt
for /f "skip=2 tokens=13" %%G in (GateIP.txt) do set GateIP=%%G
:::::::::读取DNS地址
if exist DNSServers.txt del DNSServers.txt
find "DNS Servers" ipconfig.txt >DNSServers.txt
for /f "skip=2 tokens=15" %%e in (DNSServers.txt) do set DNSIP=%%e
:::::::::设置本机IP地址
netsh interface ip set address name="本地连接" static %IP% %MASKS% %GateIP% 1
netsh int ip add dns name="本地连接" %DNSIP% index=1
:::::::::清理文件
del /q ipconfig.txt
del /q IPAddr.txt
del /q MASKAddr.txt
del /q GateIP.txt
del /q DNSServers.txt
echo 任务完成
pause
goto :eof
:choice_go2
netsh int ip set address name="本地连接" dhcp
netsh int ip set DNS name="本地连接" dhcp
echo 任务完成
pause
goto :eof
:end
[ 本帖最后由 NeverOK 于 2009-5-7 22:22 编辑 ] |
|