|
ronin
中级用户
  
积分 421
发帖 111
注册 2003-8-29
状态 离线
|
|
2005-11-10 13:42 |
|
|
willsort
元老会员
         Batchinger
积分 4432
发帖 1512
注册 2002-10-18
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
Re ronin:
IP地址等网络配置的修改和产生随机IP都没有什么问题。问题在于如何保证随机IP不会重复,100-200只有101个值,如果运行主机超过20台,便会有很高的可能性发生重复。另外,因为这个批处理可能在多个不同机器上运行,所以一般不考虑生成已占用IP列表的方法,而最好能以个机的特有值做种,以特定散列函数生成唯一对应的值。各位不知对此有何高见?当然如果 ronin 兄有其它折中的方法也不妨提出。
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.
|

※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得! |
|
2005-11-10 20:49 |
|
|
ronin
中级用户
  
积分 421
发帖 111
注册 2003-8-29
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
可以将范围拉大到100-250这样来生产随机IP地址,一般电脑数量不多,不用考虑重复,如果遇到重复会有提示,这样就重新再运行一次就行,这个问题产生是因为公司电脑系统都是用GHOST,所以IP都是一样,打算就是在GHOST完成以后运行下运行下这个批处理来避开IP重复
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.
|
|
2005-11-11 11:00 |
|
|
ronin
中级用户
  
积分 421
发帖 111
注册 2003-8-29
状态 离线
|
|
2005-11-11 20:43 |
|
|
JonePeng
金牌会员
      D◎$ Fαп
积分 4562
发帖 1883
注册 2004-1-19 来自 广东广州
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
不如将路由器设为允许DHCP,将IP地址的范围(第四位数)设为100~200,再把每台机器的IP和DNS设置都设为自动获取,这样就使每台机在启动进入系统时都自动获取IP,无须手动配置。
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.
|

----====≡≡≡≡ 我的至爱,永远是MSDOS!≡≡≡≡====----
|
|
2005-11-11 22:30 |
|
|
ronin
中级用户
  
积分 421
发帖 111
注册 2003-8-29
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
因为客户网络环境不能自己控制,我是做客服工作的
set x=%random:~-1%
set x1=%random:~-1%
;echo Random number: %x%
::把的得到的随机数写入 Wattcp.txt 文件
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
基本上已经取得IP控制在100-199范围,不知道有什么办法指定Random number在100-254范围?
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?
|
|
2005-11-11 22:40 |
|
|
ronin
中级用户
  
积分 421
发帖 111
注册 2003-8-29
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
@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
最后写出来的批处理,感觉应该是对的,但是却没有改动本地连接的IP,请问出错在那里
@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?
|
|
2005-11-11 23:00 |
|
|
无奈何
荣誉版主
      
积分 1338
发帖 356
注册 2005-7-15
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
你始终是在设置的环境变量,怎么会更改IP呢。要进入netsh 设置模式。
给你转段文章看看是否有启发。
在工作过程中会遇到在不同的网段中进行网络调试的情况,经常需要将机器在几个不同的IP地址中进行切换。在Win2000*作系统中改变IP地址较之Win98已经方便多了因为改完IP地址后不需要重启计算机,但还要进入网络属性设置中进行*作。有没有再简便一点的方法呢,比如用鼠标双击一下快捷方式就可以实现IP地址的切换?
答案是肯定的。在Win2000中用netsh命令就可以实现这个功能。首先进入命令行模式(在“开始→运行”中键入“cmd”即可进入命令行模式),在提示符下键入netsh即可进入netsh的界面。再键入int ip进入接口IP的配置模式,键入dump则列出接口IP配置信息:
C:\Documents and Settings\Administrator>netsh
netsh>
netsh>int ip
interface ip>dump
# ----------------------------------
# 接口 IP 配置
# ----------------------------------
pushd interface ip
# ″本地连接″ 的接口IP 配置(注:以下显示视具体机器情况而定)
set address name = ″本地连接″ source = static addr = 192.168.0.5 mask = 255.255.255.0
set address name = ″本地连接″ gateway = 192.168.0.2 gwmetric = 1
set dns name = ″本地连接″ source = static addr = 61.237.17.181
add dns name = ″本地连接″ addr = 211.97.168.129
add dns name = ″本地连接″ addr = 211.98.4.1
set wins name = ″本地连接″ source = static addr = none
# ″本地连接 2″ 的接口 IP 配置
set address name = ″本地连接 2″ source = dhcp
set dns name = ″本地连接 2″ source = dhcp
set wins name = ″本地连接 2″ source = dhcp
popd
# 接口 IP 配置结束
快速切换IP地址有绝招 2
现在我们可以大致了解到用netsh命令更改IP地址的方式,即通过“set address name =连接名称(连接名称要用引号括起来)source=static addr=IP地址 mask=子网掩码”来实现。
到命令行模式下用netsh直接试一下。比如要将本机的IP地址改为192.168.0.7,子网掩码为255.255.255.0,可以进行以下*作:
C:\Documents and Settings\Administrator>netsh
netsh>int ip
interface ip>set address name ="本地连接"source = static addr = 192.168.0.7 mask = 255.255.255.0
确认更改。
interface ip>exit
再用ipconfig命令核实一下:
C:\Documents and Settings\Administrator>ipconfig
Windows 2000 IP Configuration
Ethernet adapter 本地连接 2
Media State . . . . . . . . . . . Cable Disconnected
Ethernet adapter 本地连接
Connection-specific DNS Suffix .
IP Address. . . . . . . . . . . . 192.168.0.7
Subnet Mask . . . . . . . . . . . 255.255.255.0
Default Gateway . . . . . . . . . 192.168.0.2
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.
In the work process, there will be situations where network debugging is carried out in different subnets, and it is often necessary to switch the machine among several different IP addresses. Changing the IP address in the Win2000 operating system is more convenient than in Win98 (because there is no need to restart the computer after changing the IP address), but it still needs to be operated in the network properties settings. Is there a simpler method, such as double-clicking a shortcut with the mouse to realize the switching of the IP address?
The answer is yes. In Win2000, the netsh command can be used to realize this function. First, enter the command line mode (you can enter the command line mode by typing "cmd" in "Start → Run"), and type netsh at the prompt to enter the netsh interface. Then type int ip to enter the interface IP configuration mode, and type dump to list the interface IP configuration information:
C:\Documents and Settings\Administrator>netsh
netsh>
netsh>int ip
interface ip>dump
# ----------------------------------
# Interface IP configuration
# ----------------------------------
pushd interface ip
# IP configuration of "Local Area Connection" (Note: The following display depends on the specific machine situation)
set address name = "Local Area Connection" source = static addr = 192.168.0.5 mask = 255.255.255.0
set address name = "Local Area Connection" gateway = 192.168.0.2 gwmetric = 1
set dns name = "Local Area Connection" source = static addr = 61.237.17.181
add dns name = "Local Area Connection" addr = 211.97.168.129
add dns name = "Local Area Connection" addr = 211.98.4.1
set wins name = "Local Area Connection" source = static addr = none
# IP configuration of "Local Area Connection 2"
set address name = "Local Area Connection 2" source = dhcp
set dns name = "Local Area Connection 2" source = dhcp
set wins name = "Local Area Connection 2" source = dhcp
popd
# End of interface IP configuration
There is a trick to quickly switch IP addresses 2
Now we can roughly understand the way to change the IP address with the netsh command, that is, to realize it through "set address name = connection name (the connection name should be enclosed in quotes) source = static addr = IP address mask = subnet mask".
Try it directly with netsh in the command line mode. For example, to change the IP address of this computer to 192.168.0.7 and the subnet mask to 255.255.255.0, the following operations can be carried out:
C:\Documents and Settings\Administrator>netsh
netsh>int ip
interface ip>set address name ="Local Area Connection"source = static addr = 192.168.0.7 mask = 255.255.255.0
Confirm the change.
interface ip>exit
Verify with the ipconfig command again:
C:\Documents and Settings\Administrator>ipconfig
Windows 2000 IP Configuration
Ethernet adapter 本地连接 2:
Media State . . . . . . . . . . . : Cable Disconnected
Ethernet adapter 本地连接:
Connection-specific DNS Suffix . :
IP Address. . . . . . . . . . . . : 192.168.0.7
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 192.168.0.2
|
|
2005-11-12 00:27 |
|
|
ronin
中级用户
  
积分 421
发帖 111
注册 2003-8-29
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
我做了批处理,用netsh不行
I made a batch script, but netsh doesn't work
|
|
2005-11-12 14:13 |
|
|
willsort
元老会员
         Batchinger
积分 4432
发帖 1512
注册 2002-10-18
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
Re ronin:
在XP中,可以在批处理中使用 netsh 配置几乎所有的网络信息。样例如下:
netsh interface ip set address "本地连接" static 10.0.0.5 255.255.255.0 10.0.0.4 1
netsh interface ip set dns "本地连接" static 10.0.0.4
而产生随机IP可以使用set/a对随机变量%random%进行运算得到。
set rndip=%random%
set /a rndip=rndip%156+100
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
|

※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得! |
|
2005-11-12 19:14 |
|
|
ronin
中级用户
  
积分 421
发帖 111
注册 2003-8-29
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
谢谢willsort、无奈何、JonePeng帮助,已经弄好了,用下边的批处理完全没有问题
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
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
|
|
2005-11-12 21:22 |
|
|
ronin
中级用户
  
积分 421
发帖 111
注册 2003-8-29
状态 离线
|
『第 12 楼』:
关于XP检测本地连接问题
使用 LLM 解释/回答一下
接上次的问题
netsh interface ip set address "本地连接" static 192.168.1.1%x%%x1% 255.255.255.0 192.168.1.1 1
使用中发现,因为更换网卡或者其它问题,很多电脑都不是用“本地连接”,很多是用“本地连接 3”这样的,这个批处理就会出错,能不能使用批处理检测到本地连接用哪一个,或者就是直接用LOCAL替换?
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?
|
|
2005-11-14 10:38 |
|
|
unique009
初级用户
 
积分 28
发帖 8
注册 2005-11-5
状态 离线
|
『第 13 楼』:
使用 LLM 解释/回答一下
这个问题我也挺想知道
I also quite want to know this question
|
|
2005-11-14 11:17 |
|
|
willsort
元老会员
         Batchinger
积分 4432
发帖 1512
注册 2002-10-18
状态 离线
|
『第 14 楼』:
使用 LLM 解释/回答一下
—————————————— Edited by willsort ——————————————
合并主题:《17732 - 关于XP检测本地连接问题》
合并理由:二主题存在上下文的直接联系
删除回帖: voiL 和 ronin 的三篇回帖
删除理由:回帖内容为问答两主题之间关系
两位可以在以下的回帖中要求积分补偿
—————————————— Edited by willsort ——————————————
Re ronin:
关于获取连接名字,也可以使用 netsh ,目前我所找到的途径是:
netsh interface dump
用 for + set + if 可以得到并判断出其中存在的连接名。以下给出批处理中的代码示例,将得到结果存入环境变量 addressname 中,应该不太周全,建议先详细测试再实际应用。
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 ]
—————————————— 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 ]
|

※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得! |
|
2005-11-14 17:51 |
|
|
chenhui530
高级用户
   
积分 772
发帖 273
注册 2004-10-23
状态 离线
|
『第 15 楼』:
使用 LLM 解释/回答一下
获取连接名字:
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
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
|

http://www.msfans.net/bbs/ |
|
2005-11-15 14:08 |
|