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-06-27 18:25
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Batch scripts for changing IP and machine number, commonly used in internet cafes! View 3,966 Replies 12
Original Poster Posted 2007-01-10 07:34 ·  中国 广西 南宁 电信
初级用户
★★
Credits 172
Posts 52
Joined 2005-03-29 00:00
21-year member
UID 37565
Gender Male
Status Offline
Let everyone laugh, I think there are too many codes, it should still be able to be simplified, but I have low level!
I don't know if the expert can simplify the code!
Also, the subnet mask and backup DNS cannot be displayed, does any expert know how to do it?


@echo off
mode con cols=80 lines=30
:top
title ………………………………………………IP Modifier………………………………………………
cls
color 0a
::::::::::::::::::::::::::::::::::::::::::::::
:Check IP, Gateway, DNS
@echo off
setlocal enabledelayedexpansion
set IP_num=0
set Gateway_num=0
set DNS_num=0
for /f "tokens=2* delims=:" %%i in ('ipconfig /all ^| find /i "IP Address"') do (
for /f "tokens=2* delims=:" %%a in ('ipconfig /all ^| find /i "Default Gateway"') do (
for /f "tokens=2* delims=:" %%1 in ('ipconfig /all ^| find /i "DNS Servers"') do (
set IP_=%%i
set Gateway_=%%a
set DNS_=%%1
if "!IP_num!"=="0" set IP2=!IP_:~1!
if "!Gateway_num!"=="0" set Gateway2=!Gateway_:~1!
if "!DNS_num!"=="0" set DNS2=!DNS_:~1!
set /a IP_num=!IP_num!+1
set /a Gateway_num=!Gateway_num!+1
set /a DNS_num=!DNS_num!+1
)
)
)
CLS
::::::::::::::::::::::::::::::::::::::::::::::
echo.
echo IP Modifier QQ:82288252
echo ================================================================================
echo Local Information:
echo Computer Name: %userdomain%
echo Local IP: %IP2%
echo Local Gateway: %Gateway2%
echo Local DNS: %DNS2%
echo.
set /p n= Enter local number (Q to quit):
if %n% equ q exit
echo.
echo The number you entered is: %n%
echo.
set /p x= How many bits to offset the IP number:
set /a ip = %n% + %x%
echo.
echo Modifying, please wait...
::::::::::::::::::::::::::::::::::::::::::::::
:Generate VBS script to modify IP
echo strIPAddress = Array(^"192.168.1.%IP%^") ^'Modified ip >>ip.vbe
echo strSubnetMask = Array(^"255.255.255.0^") ^'Subnet mask >>ip.vbe
echo strGateway = Array(^"192.168.1.1^") ^'Gateway >>ip.vbe
echo arrDNSServers = Array(^"202.103.224.68^", ^"202.103.225.68^")^'DNS >>ip.vbe
echo strComputer = ^".^" >>ip.vbe
echo. >>ip.vbe
echo Set objWMIService = GetObject(^"winmgmts:^\\^" ^& strComputer ^& ^"^\root^\cimv2^") >>ip.vbe
echo Set colNetAdapters = objWMIService.ExecQuery _ >>ip.vbe
echo (^"Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE^") >>ip.vbe
echo. >>ip.vbe
echo For Each objNetAdapter in colNetAdapters >>ip.vbe
echo sip=objNetAdapter.IPAddress >>ip.vbe
echo ^'strIPAddress = sip ^'Keep original ip >>ip.vbe
echo. >>ip.vbe
echo strGatewayMetric = Array(1) >>ip.vbe
echo errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask) >>ip.vbe
echo errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric) >>ip.vbe
echo errDNS=objNetAdapter.SetDNSServerSearchOrder(arrDNSServers) >>ip.vbe
echo exit for ^'Only modify the settings of the first network card >>ip.vbe
echo Next >>ip.vbe
::::::::::::::::::::::::::::::::::::::::::::::
:Replace actual computer name with variable %n%
echo Windows Registry Editor Version 5.00 >Computer Name.reg
echo [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters] >>Computer Name.reg
echo "NV Hostname"="%n%" >>Computer Name.reg
echo "Hostname"="%n%" >>Computer Name.reg
::::::::::::::::::::::::::::::::::::::::::::::
:Import registry file
regedit /s Computer Name.reg
::::::::::::::::::::::::::::::::::::::::::::::
:Run VBE file to change IP address
ip.vbe
::::::::::::::::::::::::::::::::::::::::::::::
:Delete reg and vbe files
del Computer Name.reg
del ip.vbe
::::::::::::::::::::::::::::::::::::::::::::::
:Recheck IP, Gateway, DNS
@echo off
setlocal enabledelayedexpansion
set IP_num=0
set Gateway_num=0
set DNS_num=0
for /f "tokens=2* delims=:" %%i in ('ipconfig /all ^| find /i "IP Address"') do (
for /f "tokens=2* delims=:" %%a in ('ipconfig /all ^| find /i "Default Gateway"') do (
for /f "tokens=2* delims=:" %%1 in ('ipconfig /all ^| find /i "DNS Servers"') do (
set IP_=%%i
set Gateway_=%%a
set DNS_=%%1
if "!IP_num!"=="0" set IP2=!IP_:~1!
if "!Gateway_num!"=="0" set Gateway2=!Gateway_:~1!
if "!DNS_num!"=="0" set DNS2=!DNS_:~1!
set /a IP_num=!IP_num!+1
set /a Gateway_num=!Gateway_num!+1
set /a DNS_num=!DNS_num!+1
)
)
)
CLS
::::::::::::::::::::::::::::::::::::::::::::::
echo.
echo IP Modifier QQ:82288252
echo ================================================================================
echo Modification Successful:
echo.
echo Current Local Information:
echo Computer Name: %userdomain% This item takes effect after restart
echo Local IP: %IP2%
echo Local Gateway: %Gateway2%
echo Local DNS: %DNS2%
echo.
:Press any key to exit
@pause
Floor 2 Posted 2007-01-10 08:06 ·  中国 湖南 株洲 电信
初级用户
★★
Credits 135
Posts 54
Joined 2006-09-10 03:07
19-year member
UID 62265
Status Offline
Thanks
Very practical
bat+vbs+reg
Floor 3 Posted 2007-01-10 10:47 ·  中国 广东 东莞 电信
初级用户
Credits 30
Posts 12
Joined 2007-01-01 03:24
19-year member
UID 75152
Gender Male
Status Offline
Oh, what a pain... Such batch processing isn't practical in internet cafes nowadays. The most awesome thing is full automation... First, scan all IPs and MAC addresses of all machines, collect and save them. Then compile a P processing, get the MAC, then judge and find a matching one from the scanned MACs, and then change it to the set IP and computer name. That's what's considered advanced...
Floor 4 Posted 2007-01-10 10:48 ·  中国 广东 东莞 电信
初级用户
Credits 30
Posts 12
Joined 2007-01-01 03:24
19-year member
UID 75152
Gender Male
Status Offline
However, I have to thank the LZ... I've learned this batch processing again...
Floor 5 Posted 2007-01-10 18:05 ·  中国 广西 南宁 联通
初级用户
★★
Credits 172
Posts 52
Joined 2005-03-29 00:00
21-year member
UID 37565
Gender Male
Status Offline
Originally posted by a2f6k8 at 2007-1-10 10:47 AM:
Oh my god... Such batch processing is not practical in internet cafes now. The most powerful one is fully automatic... First, scan all IP and MAC addresses of all machines to collect them and save them, then compile a P processing, MAC acquisition...



Hehe, you have to say, when we install a new internet cafe, there are no client machines, only one machine for you to make the master disk. Where do you get the MAC address?
The set you mentioned is used in our own alliance internet cafe!
I post it just for everyone to study and have a reference!
There are also special small software for changing IP, but I don't like using third-party software!
This is based on the situation here!
Everyone is different, and fully automatic is not the best! It's enough if it works!
Don't you think so?

[ Last edited by wmysbbs on 2007-1-10 at 06:08 PM ]
Floor 6 Posted 2007-01-11 04:07 ·  中国 湖南 郴州 电信
初级用户
Credits 66
Posts 28
Joined 2006-11-01 04:54
19-year member
UID 69099
Gender Male
Status Offline
@echo off

set /p e=Please enter the IP segment:

set /p var=Please enter the computer name:
cls
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName" /v ComputerName /t reg_SZ /d %var% /f >nul
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ComputerName\ActiveComputerName" /v ComputerName /t reg_SZ /d %var% /f >nul
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters" /v Hostname /t reg_SZ /d %var% /f >nul
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters" /v "NV Hostname" /t reg_SZ /d %var% /f >nul
@for %%n in (a b c d e f g h i j k l m n o p q r s t u v w x y z) do call set var=%%var:%%n=%%
:loop
@if "%var:~0,1%" == "0" set var=%var:~1%
netsh interface ip set address name="Local Area Connection" source=static addr=192.168.%e%.%var% mask=255.255.255.0 gateway=192.168.%e%.1 gwmetric=0 >nul
netsh interface ip set dns name="Local Area Connection" source=static addr=61.187.191.3 register=PRIMARY >nul
netsh interface ip add dns name="Local Area Connection" addr=202.103.96.68 index=2 >nul
if %var% lss 14 goto cdkey1
if %var% lss 21 goto cdkey2
if %var% lss 28 goto cdkey3
if %var% lss 35 goto cdkey4
if %var% lss 42 goto cdkey5
if %var% lss 49 goto cdkey6
if %var% lss 56 goto cdkey7
goto :eof
:cdkey1
reg add "HKEY_CURRENT_USER\Software\Valve\Half-Life\Settings" /v ValveKey /t reg_sz /d 5RP2E-EPH3K-BR3LG-KMGTE-FN8PY /f
goto :IP
:cdkey2
reg add "HKEY_CURRENT_USER\Software\Valve\Half-Life\Settings" /v ValveKey /t reg_sz /d ULPF-ZEVK-FRWG-Q4YJ-6F2T /f
goto :IP
:cdkey3
reg add "HKEY_CURRENT_USER\Software\Valve\Half-Life\Settings" /v ValveKey /t reg_sz /d Y83K-CT4F-VL2X-4X4M-SW8X /f
goto :IP
:cdkey4
reg add "HKEY_CURRENT_USER\Software\Valve\Half-Life\Settings" /v ValveKey /t reg_sz /d 2LMD-5MUD-UY2Y-SUU2-2UUQ /f
goto :IP
:cdkey5
reg add "HKEY_CURRENT_USER\Software\Valve\Half-Life\Settings" /v ValveKey /t reg_sz /d WVNN-XDK3-PZ6Q-PN42-W9G7 /f
goto :IP
:cdkey6
reg add "HKEY_CURRENT_USER\Software\Valve\Half-Life\Settings" /v ValveKey /t reg_sz /d YM2S-PVC6-RL2T-UT89-SW8T /f
goto :IP
:cdkey7
reg add "HKEY_CURRENT_USER\Software\Valve\Half-Life\Settings" /v ValveKey /t reg_sz /d 4EFF-YZNG-6AS4-3QJQ-44YG /f
:IP
@echo Current computer-related configuration:
@echo ................................................................................
@echo off
for /f "tokens=15" %%i in ('ipconfig /all ^| find /i "ip address"') do set ip=%%i
@echo Local IP:%ip%
@echo ................................................................................
for /f "tokens=15" %%i in ('ipconfig /all ^| find /i "Subnet Mask"') do set SM=%%i
@echo Local subnet mask:%sm%
@echo ................................................................................
for /f "tokens=1* delims=:" %%i in ('ipconfig /all^|find /i "Default Gateway"') do set DG=%%j
@echo Local default gateway:%DG%
@echo ................................................................................
for /f "tokens=15" %%i in ('ipconfig /all ^| find /i "DNS server"') do set DS=%%i
@echo Local DNS server:%DS%
@echo ................................................................................
@echo Backup DNS server:202.103.96.68
@echo ................................................................................
for /f "tokens=16" %%i in ('ipconfig /all ^| find /i "Host Name"') do set HN=%%i
@echo Computer name is :%HN%
@echo ................................................................................
@echo Press any key to perform network test.
@pause >nul
@ping 61.187.191.3
@echo Test completed.. Press any key to exit.
@pause > nul

I wrote it after using it for a while. Also, because I need to make a Internet café system. Like the building owner, I don't like to use any IP modification tools.

Of course, I did it according to some local network settings. For example, DNS. Enter the segment just enter a number.
For example, if your gateway is 192.168.1.1, then you enter "1". The IP is changed according to the computer name.
IF the computer name is a046, then the IP is 192.168.1.46. For the CDKEY of CS, just look at it.
Just started learning. I hope everyone doesn't laugh. The content is a bit low-intelligence
Floor 7 Posted 2007-01-11 05:15 ·  IANA 局域网IP(Private-Use)
新手上路
Credits 6
Posts 2
Joined 2006-12-30 04:37
19-year member
UID 74971
Gender Male
Status Offline
Excuse me, can the above code run under the user permissions of Windows 2000 or XP?
Floor 8 Posted 2007-01-11 10:13 ·  中国 湖南 郴州 电信
初级用户
Credits 66
Posts 28
Joined 2006-11-01 04:54
19-year member
UID 69099
Gender Male
Status Offline
Floor 9 Posted 2007-03-08 21:47 ·  中国 广东 东莞 电信
新手上路
Credits 2
Posts 1
Joined 2007-01-09 11:21
19-year member
UID 75945
Gender Male
Status Offline
Good
Floor 10 Posted 2007-03-08 22:17 ·  中国 河南 周口 联通
初级用户
Credits 57
Posts 28
Joined 2006-11-06 05:32
19-year member
UID 69754
Gender Male
From 中国
Status Offline
Not bad, very good? I want to write but don't know how, not very understanding, and I'm learning batch processing. Thanks to the landlord, I've learned a lot.
Floor 11 Posted 2007-03-16 09:27 ·  中国 湖北 武汉 电信
中级用户
★★
Credits 452
Posts 202
Joined 2006-12-21 13:46
19-year member
UID 74161
Gender Female
Status Offline
The principle is very simple!! But it's very practical. Actually, sometimes it's just about re-burning the system disk. You can completely make a batch file and put it on the D drive. First, collect the local IP-related information, and then after burning the system disk well, run this batch file to restore the previous IP ==. Moreover, what you have now is obviously used after hard disk cloning, but there is no boot auto-start, and it deletes itself automatically after setting ==. Also, someone has already made one before you, you can go and have a look
http://cn-dos.net/forum/viewthread.php?tid=26870&fpage=1&highlight=IP
Floor 12 Posted 2007-05-30 15:59 ·  中国 广东 揭阳 电信
初级用户
Credits 20
Posts 9
Joined 2007-05-29 14:32
19-year member
UID 89649
Gender Male
Status Offline
Sometimes it works, sometimes it doesn't
Floor 13 Posted 2007-05-30 19:17 ·  中国 广东 广州 黄埔区 电信
中级用户
★★
Credits 326
Posts 152
Joined 2007-05-04 06:16
19-year member
UID 87412
Gender Male
Status Offline
Forum Jump: