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-02 02:47
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Ghost automatically to change IP cannot find the local connection [Help][Closed] View 1,486 Replies 4
Original Poster Posted 2006-08-17 21:52 ·  中国 广西 钦州 电信
初级用户
Credits 38
Posts 14
Joined 2006-08-16 15:37
19-year member
UID 60649
Gender Male
Status Offline
I don't know if you've seen that batch script online that automatically changes the IP after ghosting. Because that batch script has a really critical flaw, which is that it can only change the first network card, which is (Local Area Connection). If you ghost it over, and the network card of that computer is not the same model, or it's not in the same IPC slot, then there will be (Local Area Connection 2) or (Local Area Connection 3). I myself have tried using find to extract it, and every time I need it, there's an extra :. I don't know what to do.
=================================
ipconfig /all >ipconfig.txt
find "Ethernet adapter" ipconfig.txt >connect.txt
for /f "skip=2 tokens=3" %%c in (connect.txt) do set connect=%%c
=============================================
This is the connect.txt I got
=============================================
---------- IPCONFIG.TXT
Ethernet adapter 本地连接 2:

=============================================
I don't know how to get (Local Area Connection 2)
Is there any other way to get it? What I get all have (Local Area Connection 2:) and an extra dot added

PS. Sorry moderator, I didn't read the forum rules clearly just now. I'm a newbie, I need to understand the role of for before speaking
But now I really want to know, I'm learning ^^

[ Last edited by jzl168 on 2006-8-17 at 22:43 ]
Floor 2 Posted 2006-08-17 22:41 ·  中国 湖北 荆门 电信
荣誉版主
★★★
Credits 2,013
Posts 718
Joined 2006-02-18 07:07
20-year member
UID 50550
Status Offline
Well, first of all, combine the first two sentences:
ipconfig /all | find "Ethernet adapter" >connect.txt
Of course, it can also be used directly in for /f without generating a temporary file.
Second, if you want to get "(Local Area Connection 2)", then after enabling delayed environment variables (setlocal ENABLEDELAYEDEXPANSION), in the do statement of for, assign "Local Area Connection 2:" to the variable connect, and then remove the last colon by outputting!connect:~0,-1!.
Of course, this problem doesn't have to be solved with for. Many times, we should open our minds:

@echo off
set "connect=Local Area Connection"
ipconfig /all | find "Ethernet adapter" | find "2" && set "connect=Local Area Connection 2"
ipconfig /all | find "Ethernet adapter" | find "3" && set "connect=Local Area Connection 3"

Not tested, just providing ideas. If you want to reflect more automation, you can put the search conditions in for /l and then use goto to jump.
To learn the usage of for, you can flip through the old posts in the forum when you have nothing to do. After understanding all of them, you will be a master of batch processing. Also, refer to my signature.
Floor 3 Posted 2006-08-17 22:48 ·  中国 广西 钦州 电信
初级用户
Credits 38
Posts 14
Joined 2006-08-16 15:37
19-year member
UID 60649
Gender Male
Status Offline
Thanks to the moderator. But I still follow my original train of thought. I already understand the above.
Basically, I read two or three hours of old posts here every day. I'm not very smart. Reading more and learning more may be helpful.
Maybe I just started learning not long ago, so the train of thought hasn't come up yet.
Floor 4 Posted 2006-08-17 22:52 ·  中国 四川 成都 鹏博士宽带
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
If you just want to remove the colon, you can do it like this:


@echo off
setlocal enabledelayedexpansion
for /f "skip=2 tokens=3" %%i in (connect.txt) do (
set var=%%i
set "var=!var::=!"
)
echo %var%
pause
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Floor 5 Posted 2006-08-18 08:30 ·  中国 山东 菏泽 电信
银牌会员
★★★
Credits 1,246
Posts 488
Joined 2003-11-11 00:00
22-year member
UID 12699
Gender Male
Status Offline
Learning
Forum Jump: