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-06-25 08:25
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Closed: About the problem of automatically changing IP address (XP) View 7,879 Replies 22
Floor 16 Posted 2005-11-15 16:27 ·  中国 山西 太原 中移铁通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
Re chenhui530:

The methods of you and I should both have ignored the situations where there are spaces and colons in the connection name. I made a slight modification based on your code.

Interestingly, it was found that in the command output of ipconfig, the end of each line of text is two carriage returns (0x0D) and one newline (0x0A). So when I initially tested with delims=2*, a series of interesting setting confusions occurred, such as I could use it to hide the first character of the environment variable name. But later I remembered that Brother Wu Nai He first discovered this phenomenon in the forum, and the link is as follows:

(Solved) Please ask how to capture a specific line of text in a file
http://www.cn-dos.net/forum/viewthread.php?tid=17443#pid102925

I don't know if this is a bug in the program or a special requirement in some special applications. But it does bring some small troubles to our use in batch processing.


@echo off
for /f "skip=3 tokens=2*" %%a in ('ipconfig') do set AccessName=%%b&& goto AccName2

:AccName2
set AccessName=%AccessName:~0,-2%
echo Access: "%AccessName%"


[ Last edited by willsort on 2005-11-15 at 16:29 ]
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 17 Posted 2005-11-15 20:22 ·  中国 广东 梅州 电信
中级用户
★★
Credits 421
Posts 111
Joined 2003-08-29 00:00
22-year member
UID 9153
Gender Male
Status Offline
I tried it, and it should run without problems. Have you considered the situation of multiple network cards?
Floor 18 Posted 2005-11-17 13:27 ·  中国 福建 泉州 晋江市 电信
初级用户
Credits 51
Posts 14
Joined 2005-11-06 20:02
20-year member
UID 44706
Gender Male
Status Offline
### Translation
@echo off
for /f "skip=3 tokens=2*" %%a in ('ipconfig') do set AccessName=%%b&& goto AccName2

:AccName2
set AccessName=%AccessName:~0,-2%


I would like to ask. Why is this set AccessName=%%b here.
Also, what does the SET AccessName=%AccessName:~0,-2% command do?

### Note
The original text is a mix of Chinese and English code blocks. The translation is done while keeping the code blocks and Chinese questions as per requirements.
Floor 19 Posted 2005-11-18 15:46 ·  中国 广东 梅州 电信
中级用户
★★
Credits 421
Posts 111
Joined 2003-08-29 00:00
22-year member
UID 9153
Gender Male
Status Offline
Tested in win2000, there is "Local Area Connection 2", an error occurs, and the parameters are found to be correct

@echo off
for /f "skip=3 tokens=2*" %%a in ('ipconfig') do set AccessName=%%b&& goto AccName2

:AccName2
set AccessName=%AccessName:~0,-2%
echo Access: "%AccessName%"
set x=%random:~-1%
set x1=%random:~-1%
netsh interface ip set address "%AccessName%" static 192.168.1.1%x%%x1% 255.255.255.0 192.168.1.1 1

The command running result is: An invalid port was specified Local Area Connection 2
Floor 20 Posted 2005-11-18 19:42 ·  中国 广东 梅州 电信
中级用户
★★
Credits 421
Posts 111
Joined 2003-08-29 00:00
22-year member
UID 9153
Gender Male
Status Offline
netsh interface ip set dns "%AccessName%" static 192.168.1.1,192.168.1.2,192.168.1.3

Entering multiple DNS servers in this way may cause an error. How to handle it?
Floor 21 Posted 2005-11-28 23:08 ·  中国 广东 梅州 电信
中级用户
★★
Credits 421
Posts 111
Joined 2003-08-29 00:00
22-year member
UID 9153
Gender Male
Status Offline
Batch script to set multiple DNS. The above are telecom, China Tietong, and Unicom DNS respectively.

Automatically setting IP and DNS has been tested under XP and WIN2003, but will cause errors under WIN2000
Floor 22 Posted 2005-11-30 13:22 ·  中国 山西 临汾 中移铁通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
Re ronin:

Floor 17: Because my test machine does not have a multi-network card situation, so I can't test and improve it.

Floor 19: There is a selection strategy problem in the case of multiple connections, this is not a problem of the batch processing itself.

Floors 20/21: It may not pass under Win2000 for two possible reasons: 1. Does not support or incomplete support for the netsh command; 2. The output of ipconfig is different from XP. Wait and see after seeing the output results of netsh and ipconfig, redirect it to a text and upload it as an attachment.

Re zero:

Use set /? to check the command line help of set to get a clear answer.

[ Last edited by willsort on 2005-11-30 at 13:23 ]
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 23 Posted 2005-11-30 17:44 ·  中国 广东 梅州 电信
中级用户
★★
Credits 421
Posts 111
Joined 2003-08-29 00:00
22-year member
UID 9153
Gender Male
Status Offline
1. Does not support or incompletely supports the netsh command
I estimate this reason is relatively common
Forum Jump: