![]() |
China DOS Union-- Unite DOS · Advance DOS · Grow DOS --Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum |
| Guest | Log in | Register | Members | Search | China DOS Union |
|
中国DOS联盟论坛 The time now is 2026-09-29 18:11 |
47,813 topics / 349,918 posts / today 0 new / 48,278 members |
| DOS批处理 & 脚本技术(批处理室) » Closed: About the problem of automatically changing IP address (XP) |
| Printable Version 8,702 / 22 |
| Floor16 willsort | Posted 2005-11-15 16:27 |
| 元老会员 Posts 1,512 Credits 4,432 | |
|
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. [ Last edited by willsort on 2005-11-15 at 16:29 ] |
|
| Floor17 ronin | Posted 2005-11-15 20:22 |
| 中级用户 Posts 111 Credits 421 | |
|
I tried it, and it should run without problems. Have you considered the situation of multiple network cards?
|
|
| Floor18 zreo | Posted 2005-11-17 13:27 |
| 初级用户 Posts 14 Credits 51 | |
|
### Translation
@echo off 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. |
|
| Floor19 ronin | Posted 2005-11-18 15:46 |
| 中级用户 Posts 111 Credits 421 | |
|
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 |
|
| Floor20 ronin | Posted 2005-11-18 19:42 |
| 中级用户 Posts 111 Credits 421 | |
|
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? |
|
| Floor21 ronin | Posted 2005-11-28 23:08 |
| 中级用户 Posts 111 Credits 421 | |
|
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 |
|
| Floor22 willsort | Posted 2005-11-30 13:22 |
| 元老会员 Posts 1,512 Credits 4,432 | |
|
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 ] |
|
| Floor23 ronin | Posted 2005-11-30 17:44 |
| 中级用户 Posts 111 Credits 421 | |
|
1. Does not support or incompletely supports the netsh command
I estimate this reason is relatively common |
|
| Prev 1 2 |
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |