China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-03 20:27
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Ask] How to change the IP address using batch processing View 2,029 Replies 6
Original Poster Posted 2006-09-27 10:44 ·  中国 浙江 杭州 电信
初级用户
Credits 34
Posts 12
Joined 2006-09-25 04:45
19-year member
UID 63588
Gender Male
Status Offline
Since I often need to use two static IPs, it's troublesome to keep changing them. I wonder if there is a good batch processing to complete this action.


————————————I am the divider——————————————


*********************************
Board management record
*********************************
Operation: Change title
Reason: Original format does not conform to the board rules
Original title: Ask for a batch processing
Execution: 3742668
Punishment: First offense, forgiven.
Remarks: 1. It is recommended to read the top - sticked board rules before posting
2. How to change the title?
Click the edit button at the lower right corner of the posted post, and then edit it.
**********************************


[ Last edited by 3742668 on 2006 - 9 - 29 at 09:10 ]
Floor 2 Posted 2006-09-28 05:35 ·  中国 山东 淄博 联通
中级用户
★★
Credits 272
Posts 99
Joined 2006-06-02 09:12
20-year member
UID 56414
Status Offline
I'm sorry. I made a mistake. Let's start over.


@echo off

set IP1=192.168.0.200
set mask1=255.255.255.0
set gate1=192.168.0.1
set IP2=192.168.0.100
set mask2=255.255.255.0
set gate2=192.168.0.1

goto cp%~x0

:cp.bat
netsh interface ip set address name="Local Area Connection" source=static addr=%IP1% mask=%mask1% gateway=%gate1% gwmetric=1
ipconfig
pause
start /b cmd /c ren "%~f0" "%~n0.cmd"
goto end 2>nul

:cp.cmd
netsh interface ip set address name="Local Area Connection" source=static addr=%IP2% mask=%mask2% gateway=%gate2% gwmetric=1
ipconfig
pause
start /b cmd /c ren "%~f0" "%~n0.bat"
:end
Floor 3 Posted 2006-09-28 23:31 ·  中国 浙江 杭州 电信
初级用户
Credits 34
Posts 12
Joined 2006-09-25 04:45
19-year member
UID 63588
Gender Male
Status Offline
Thank you very much, upstairs. I'll give it a try!!
Floor 4 Posted 2006-09-29 11:16 ·  中国 浙江 杭州 电信
初级用户
Credits 34
Posts 12
Joined 2006-09-25 04:45
19-year member
UID 63588
Gender Male
Status Offline
Thanks to the moderator's instruction, heh heh
Floor 5 Posted 2007-03-13 14:45 ·  中国 北京 海淀区 IDC机房
初级用户
☆流星雨◇帅气冲天狂
Credits 24
Posts 21
Joined 2007-03-09 08:10
19-year member
UID 81176
Gender Male
From 广东
Status Offline
The one on the 2nd floor is不错, okay,
Floor 6 Posted 2007-03-13 23:04 ·  中国 安徽 马鞍山 电信
中级用户
★★
Credits 493
Posts 228
Joined 2007-02-16 00:38
19-year member
UID 79596
Gender Male
From 安徽
Status Offline

ipconfig
...
start /b cmd /c ren "%~f0" "%~n0.cmd"
...
start /b cmd /c ren "%~f0" "%~n0.bat"
...


Why execute the above statements???

Also, if the system is in English,
I think we need to make a judgment on the "Local Area Connection"!

[ Last edited by xycoordinate on 2007-3-13 at 10:07 AM ]
Floor 7 Posted 2007-03-14 05:04 ·  中国 广东 广州 番禺区 电信
中级用户
★★
脚本爱好者
Credits 238
Posts 93
Joined 2007-03-11 13:38
19-year member
UID 81417
Gender Male
From GZ
Status Offline
Actually, it's very simple (change the IP and DNS in the code to values suitable for your location):
@echo off
color 1e
title IP Address, Gateway, DNS Automatic Setup Program
echo.
echo Setting IP address, gateway, and DNS, please wait...
echo.
netsh int ip set address name="Local Area Connection" source=static addr=192.168.1.168 mask=255.255.255.0
netsh int ip set address name="Local Area Connection" gateway=192.168.1.1 gwmetric=1
netsh int ip set dns name="Local Area Connection" source=static addr=202.96.128.166 register=PRIMARY
netsh int ip add dns name="Local Area Connection" addr=61.144.56.101 index=2
netsh int ip set wins name="Local Area Connection" source=static addr=none
exit

[ Last edited by axi on 2007-3-15 at 11:31 PM ]
Forum Jump: