中国DOS联盟论坛

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-02 01:34
48,037 topics / 350,122 posts / today 2 new / 48,250 members
DOS批处理 & 脚本技术(批处理室) » Ghost automatically to change IP cannot find the local connection [Help][Closed]
Printable Version  1,485 / 4
Floor1 jzl168 Posted 2006-08-17 21:52
初级用户 Posts 14 Credits 38
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 ]
Floor2 3742668 Posted 2006-08-17 22:41
荣誉版主 Posts 718 Credits 2,013
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:

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.
Floor3 jzl168 Posted 2006-08-17 22:48
初级用户 Posts 14 Credits 38
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.
Floor4 namejm Posted 2006-08-17 22:52
荣誉版主 Posts 1,737 Credits 5,226 From 成都
If you just want to remove the colon, you can do it like this:

Floor5 wang6610 Posted 2006-08-18 08:30
银牌会员 Posts 488 Credits 1,246
Learning
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023