In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
Editor to share with you how to realize the batch processing of IP\ machine name\ working group for network management. I hope you will get something after reading this article. Let's discuss it together.
There are hundreds of machines in the department I am in charge of. I need to restore the original configuration after reinstallation. I have used many methods:
1: change it manually, don't talk about this one.
2: use netsh dump + file and netsh-f + file to change, but it is useless to format the whole disk.
3: use a dedicated Mini Program to change the ip address, but you still need to specify the IP manually
Finally, I came up with the following ideas:
1: first implement: netsh interface ip to change IP
2: use wmic computersystem to modify the workgroup
3: use reg add to change the machine name
4: because the reboot does not take effect until the machine name is changed, use: reboot.inf to restart
5: later, the new machine name and ip configuration are added, using the machine's serial number (associated machine: wmic bios get SerialNumber) as the machine name, and the last bit of the ip address is random.
Because the serial number can be read through wmic, it is much more convenient when we can register the local network configuration.
6: finally, put the corresponding table such as IP address in bat to prevent bat from calling other files.
7: after realizing the above functions, I can package the bat file into the gho file and set it automatically after recovery and restart. I don't want to do anything else, and users can use it. If necessary, you can add and delete yourself automatically after execution.
The whole code is as follows: (welcome to continue to optimize and organize)
The code is as follows:
@ echo off & code by m13632750052
For / f "tokens=12 delims="% I in ('ipconfig/ all ^ | find "Physical Address"') do set localmac=%%i
Echo looks up the corresponding machine name through the MAC address% localmac%
For / f "skip=90 tokens=1,2,3,4 delims="% I in (% ~ f0) do (
If [% k] = = [% localmac%] set Name=%%i
If [% k] = = [% localmac%] set IP=%%j
If [% k] = = [% localmac%] set MAC=%%k
If [% k] = = [% localmac%] set Workgroup=%%l
Set mask=255.255.0.0
Set gway=168.30.1.233
Set dns=168.1.4.147
Set dns2=168.1.6.243
)
Echo displays search results code by cn-dos breakme
If defined Name (echo Name% IP% mac% Workgroup%) else (goto newset)
: Enterset
For / l%% I in do ping-n 2 127.0.0% I > nul & & @ echo. Modify the machine name after% I s.
Reg add "HKEY_CURRENT_USER\ Software\ Microsoft\ Windows\ ShellNoRoam" / v @ / t REG_SZ / d "% Name%" / f
Reg add "HKLM\ SYSTEM\ CurrentControlSet\ Control\ ComputerName\ ComputerName" / v "ComputerName" / t REG_SZ / d "% Name%" / f
Reg add "HKLM\ SYSTEM\ CurrentControlSet\ Control\ ComputerName\ ActiveComputerName" / v "ComputerName" / t REG_SZ / d "% Name%" / f
Reg add "HKLM\ SYSTEM\ CurrentControlSet\ Services\ Eventlog" / v "ComputerName" / t REG_SZ / d "% Name%" / f
Reg add "HKLM\ SYSTEM\ CurrentControlSet\ Control\ ComputerName\ ComputerName" / v "ComputerName" / t REG_SZ / d "% Name%" / f
Reg add "HKLM\ SYSTEM\ CurrentControlSet\ Services\ Tcpip\ Parameters" / v "NV Hostname" / t REG_SZ / d "% Name%" / f
Reg add "HKLM\ SYSTEM\ CurrentControlSet\ Services\ Tcpip\ Parameters" / v "Hostname" / t REG_SZ / d "% Name%" / f
Echo refreshes the registry
If exist c:\ winnt (secedit / refreshpolicy machine_policy / enforce) else (gpupdate / force)
Echo Modification working Group
Wmic computersystem where Name= "Name%" call JoinDomainOrWorkgroup Name= "Workgroup%"
Wmic computersystem where Name= "ComputerName%" call JoinDomainOrWorkgroup Name= "Workgroup%"
Echo modifies IP
:: find the connection name corresponding to MAC
For / f "tokens=1,2,3,4,5,6 delims=-" An in ("MAC%") do set MacWMIC=%%A:%%B:%%C:%%D:%%E:%%F
For / f "skip=2 tokens=2* delims==" An in ('WMIC NIC WHERE "MACAddress='%MacWMIC%' AND NetConnectionID invalid null" GET NetConnectionID / value') do set "ConnName=%%A"
If not defined ConnName set ConnName= "Local connection"
Netsh interface ip set address name= "ConnName%" source=static addr=%IP% mask=%mask%
Netsh interface ip set address name= "ConnName%" gateway=%gway% gwmetric=0
Netsh interface ip set dns name= "ConnName%" source=static addr=%dns% register=PRIMARY
Netsh interface ip add dns name= "ConnName%" addr=%dns2% index=2
Netsh interface ip set wins name= "ConnName%" source=static addr=none
Echo arp binding IP% MAC%
Arp-d
Arp-s% IP%% MAC%
Echo arp binding gateway% gway%, if the network is not available, the default gateway MAC:00-00-5e-00-01-01 will be used
Ping-n 2% gway% > nul 2 > nul
If [% ERRORLEVEL%] = [1] (set GateMac=00-00-5e-00-01-01) else (
For / f "skip=3 tokens=2"% H in ('arp-a% gway%') do set GateMac=%%H
)
Cmd / c arp-s% gway%% GateMac%
For / l%% I in do ping-n 2 127.0.0% I > nul & & @ echo. Restart the computer after% I s.
Setlocal
Cd/d temp%
Echo [version] > reboot.inf
Set inf=InstallHinfSection DefaultInstall
Echo signature=$chicago$ > > reboot.inf
Echo [defaultinstall] > > reboot.inf
Rundll32 setupapi,%inf% 1% temp%\ reboot.inf
Del reboot.inf
EXIT
: newset
Echo your machine may be a new machine, you need to enter ip manually
For / f "tokens=1,2 delims=="% I in ('wmic bios get SerialNumber / value^ | find "="') do set Name=%%j
If not defined Name set / p Name= Please enter the name of the new machine
Echo machine name:% Name%
Call: select "Physical Address"mac"
Echo mac:% mac%
Set / an aa=%random%%%9
Set IP=168.30.7.1%aa%
Set mask=255.255.0.0
Set gway=168.30.1.233
Set dns=168.1.4.147
Set dns2=168.1.6.243
Set Workgroup=vga00l
Echo IP configuration:% ip% mask%% gway%% dns%% dns2%% Workgroup%
For / l%% I in do ping-n 2 127.0.0% I > nul & & @ echo. Modify the machine name after% I s.
Goto Enterset
: select
For / f "tokens=2 delims=:"% I in ('ipconfig / all ^ | findstr / I / all% 1') do if not "!% ~ 2!" = "" set "% ~ 2%% I"
GOTO: eof
After reading this article, I believe you have a certain understanding of "how to automatically change IP\ machine name\ batch processing of the working group for network management. If you want to know more about it, please follow the industry information channel. Thank you for your reading!"
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.