![]() |
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-08-10 16:53 |
47,811 topics / 349,897 posts / today 0 new / 48,256 members |
| DOS批处理 & 脚本技术(批处理室) » Closed: About the problem of automatically changing IP address (XP) |
| Printable Version 8,238 / 22 |
| Floor1 ronin | Posted 2005-11-10 13:42 |
| 中级用户 Posts 111 Credits 421 | |
|
Reference materials:
http://www.cn-dos.net/forum/viewthread.php?tid=16990&fpage=12 http://www.cn-dos.net/forum/viewthread.php?tid=17272&fpage=8 The question is: Use batch processing to automatically modify the IP address, subnet mask, and gateway of XP. Since it is for company use and cannot all use the same IP address, it is hoped to give an IP range such as 192.168.1.*, where * is randomly assigned, and the range is limited such as 100 - 200. How to write this batch processing file for everyone? Refer to the information found online, everyone can also refer to http://www.btvgd.com/net/bbs/topic.php?filename=f_8&forumid=10 [ Last edited by willsort on 2005-11-30 at 19:53 ] |
|
| Floor2 willsort | Posted 2005-11-10 20:49 |
| 元老会员 Posts 1,512 Credits 4,432 | |
|
Re ronin:
There are no problems with modifying network configurations such as IP addresses and generating random IPs. The problem is how to ensure that random IPs do not repeat. There are only 101 values from 100 to 200. If there are more than 20 running hosts, there is a high possibility of repetition. Also, since this batch script may run on multiple different machines, the method of generating an occupied IP list is generally not considered. It is better to use a unique value specific to each machine as a seed and generate a unique corresponding value with a specific hash function. What do you all think about this? Of course, if Brother ronin has other compromise methods, feel free to propose them. |
|
| Floor3 ronin | Posted 2005-11-11 11:00 |
| 中级用户 Posts 111 Credits 421 | |
|
You can expand the range to 100-250 to generate random IP addresses. Generally, there are not many company computers, so duplication doesn't need to be considered. If duplication is encountered, there will be a prompt, and then you can just run it again. This problem occurs because the company's computer systems all use GHOST, so the IPs are the same. The plan is to run this batch script after GHOST is completed to avoid IP duplication.
|
|
| Floor4 ronin | Posted 2005-11-11 20:43 |
| 中级用户 Posts 111 Credits 421 | |
|
http://www.pzz.cn/bbs/read.php?tid=4658&fpage=1
I tried but didn't succeed |
|
| Floor5 JonePeng | Posted 2005-11-11 22:30 |
| 金牌会员 Posts 1,883 Credits 4,562 From 广东广州 | |
|
It is better to set the router to allow DHCP, set the range of the IP address (the fourth digit) to 100-200, and then set the IP and DNS of each machine to obtain automatically. In this way, each machine can automatically obtain an IP when it starts and enters the system, without manual configuration.
|
|
| Floor6 ronin | Posted 2005-11-11 22:40 |
| 中级用户 Posts 111 Credits 421 | |
|
Because the customer's network environment cannot be controlled by themselves, I am doing customer service work.
set x=%random:~-1% set x1=%random:~-1% ;echo Random number: %x% ::Write the obtained random number to the Wattcp.txt file echo IP=192.168.1.1%x%%x1%> Wattcp.txt echo NETMASK=255.255.255.0>> Wattcp.txt echo GATEWAY=192.168.1.1>> Wattcp.txt Basically, the IP has been obtained and controlled in the range of 100-199. I don't know what method there is to specify the Random number in the range of 100-254? |
|
| Floor7 ronin | Posted 2005-11-11 23:00 |
| 中级用户 Posts 111 Credits 421 | |
|
@echo off
set x=%random:~-1% set x1=%random:~-1% set eth="本地连接" set ip=192.168.1.1%x%%x1% set gateway=192.168.1.1 set netmasks=255.255.255.0 The final batch script I wrote seems to be correct, but it didn't change the IP of the "Local Area Connection". Where is the mistake? |
|
| Floor8 无奈何 | Posted 2005-11-12 00:27 |
| 荣誉版主 Posts 356 Credits 1,338 | |
|
You are always setting environment variables, how can you change the IP? You need to enter the netsh setup mode.
Let's transfer a paragraph of article to see if it inspires you.
|
|
| Floor9 ronin | Posted 2005-11-12 14:13 |
| 中级用户 Posts 111 Credits 421 | |
|
I made a batch script, but netsh doesn't work
|
|
| Floor10 willsort | Posted 2005-11-12 19:14 |
| 元老会员 Posts 1,512 Credits 4,432 | |
|
Re ronin:
In XP, you can use netsh in batch processing to configure almost all network information. The sample is as follows: netsh interface ip set address "Local Area Connection" static 10.0.0.5 255.255.255.0 10.0.0.4 1 netsh interface ip set dns "Local Area Connection" static 10.0.0.4 And to generate a random IP, you can use set /a to perform operations on the random variable %random%. set rndip=%random% set /a rndip=rndip%156+100 |
|
| Floor11 ronin | Posted 2005-11-12 21:22 |
| 中级用户 Posts 111 Credits 421 | |
|
Thanks to willsort, Wu Nai He, and JonePeng for help. It's already fixed. The following batch script works perfectly:
set x=%random:~-1% set x1=%random:~-1% netsh interface ip set address "本地连接" static 192.168.1.1%x%%x1% 255.255.255.0 192.168.1.1 1 |
|
| Floor12 ronin | Posted 2005-11-14 10:38 |
| 中级用户 Posts 111 Credits 421 | |
|
Continuing from the previous question, the command is `netsh interface ip set address "本地连接" static 192.168.1.1%x%%x1% 255.255.255.0 192.168.1.1 1`. During use, it is found that because of changing the network card or other problems, many computers do not use "Local Area Connection", many use "Local Area Connection 3" and so on, this batch processing will be wrong. Can the batch processing detect which one the local connection is, or just replace it with LOCAL?
|
|
| Floor13 unique009 | Posted 2005-11-14 11:17 |
| 初级用户 Posts 8 Credits 28 | |
|
I also quite want to know this question
|
|
| Floor14 willsort | Posted 2005-11-14 17:51 |
| 元老会员 Posts 1,512 Credits 4,432 | |
|
—————————————— Edited by willsort —————————————— Merge topic: "17732 - About XP detecting local connection problem" Merge reason: The two topics have direct contextual connections Delete posts: Three posts by voiL and ronin Delete reason: The content of the posts is about the relationship between the two Q&A topics The two can request points compensation in the following posts —————————————— Edited by willsort —————————————— Re ronin: Regarding obtaining the connection name, you can also use netsh. The way I have found so far is: netsh interface dump Using for + set + if, you can obtain and judge the connection names existing in it. The following is an example of code in a batch file, which will store the result in the environment variable addressname. It should not be fully comprehensive. It is recommended to test it in detail before actual application. for /f "tokens=1,2,3" %%a in ('netsh interface dump') do if "%%b"=="address" echo %%a %%b%%c [ Last edited by willsort on 2005-11-14 at 20:32 ] |
|
| Floor15 chenhui530 | Posted 2005-11-15 14:08 |
| 高级用户 Posts 273 Credits 772 | |
|
Get connection name:
for /f "skip=3 tokens=1,2,3 delims=: " %%a in ('ipconfig') do for %%A in (%%c) do set a=%%A && goto view :view echo %a% pause |
|
| 1 2 Next |
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |