EDIT: I have updated my zone_ip update script to version 1.1. It now supports rebooting the server after changing the IP. Change log below:
Change Log:
Virus Total Scan:- Stores old IP decimal in text file for checking against new IP decimal found and changes Zone_Settings sql table if there's a difference.
- Creates folder "batch_files" within DSP folder to store text file.
- Added variables to be set for everything that needs to be edited in the batch file so that it's easier for editing.
- Added 2nd batch file that auto-restarts the server after changing the IP and is set to run in a loop to auto-update the IP as soon as it changes.
https://www.virustotal.com/en/file/47d2 ... 387311772/
Download is the zip file in the attachment.
Setup Instructions For No Auto-Reboot of Server:
1. Extract the batch files from the zip file to anywhere you want.
2. Right click on the batch file Update_ZoneIP_v1.1.bat and select "edit" to open it in notepad (you can use any text editor you want)
3. Under the heading "::Set Variables", change each of the values to what you need. There are descriptions in the batch file for what each one is.
4. Save and run the batch file and that's it you're done. From now on all you have to do is double click that batch file everytime your dynamic dns IP changes. To double check to make sure it changed the zoneip just open up the zone_settings table in your mysql database and it should have a different value for the zoneip field.
Code: Select all
echo off
::***************************************
::* *
::* ZoneIP Update Script v1.1 *
::* By Kloe *
::* *
::***************************************
::Set Variables
::=============
::DSP server root path. Example: C:\DSP
set serverpath="PATH_TO_DSP_ROOT"
::Dynamic DNS Hostname. Example: darkstarproject.dyndns.org
set ddnshost=YOUR_DDNS_HOSTNAME
::mysql host address
set dbhost=localhost
::mysql database username
set dbuser=root
::mysql database password
set dbpass=DB_PASSWORD
::mysql database name
set dbname=DB_NAME
cls
::Creates a folder for storing output files if it does not exist
::==============================================================
if not exist %serverpath%\Batch_Files md %serverpath%\Batch_Files
::Extract IP Octects from nslookup of Dynamic DNS Hostname
::========================================================
for /f "tokens=5 delims=:." %%i in ('nslookup %ddnshost% ^| findstr /C:"Address:"') do set a=%%i
for /f "tokens=4 delims=:." %%j in ('nslookup %ddnshost% ^| findstr /C:"Address:"') do set b=%%j
for /f "tokens=3 delims=:." %%k in ('nslookup %ddnshost% ^| findstr /C:"Address:"') do set c=%%k
for /f "tokens=2 delims=:." %%l in ('nslookup %ddnshost% ^| findstr /C:"Address:"') do set d=%%l
cls
::Convert Octets to Decimal
::=========================
::Octet Format Example: address 192.168.1.1 would be read in reverse order (1.1.168.192)
::So octet1 is 1, octet2 is 1, octet3 is 168, and octet4 is 192
set /a octet1=%a%*(256*256*256)
set /a octet2=%b%*(256*256)
set /a octet3=%c%*256
set /a octet4=%d%*1
set /a ipdecimal=%octet1%+%octet2%+%octet3%+%octet4%
::If file storing old IP Decimal value exists go to ipcheck otherwise go to ipexport
::==================================================================================
if exist %serverpath%\Batch_Files\ip_decimal.txt goto ipcheck
goto ipexport
:ipcheck
::Check to see if %ipdecimal% has changed to see if your public IP has changed
::===============================================================================
set /P oldip=<%serverpath%\Batch_Files\ip_decimal.txt
if %oldip% == %ipdecimal% (
cls
ECHO.
ECHO.
ECHO IP address Hasn't Changed.
pause
goto end
)
goto ipexport
:ipexport
::Run a Query that updates the zoneip field in the table "zone_settings" to update the IP address in sql
mysql -h %dbhost% -u %dbuser% -p%dbpass% %dbname% -e "UPDATE zone_settings SET zoneip = '%ipdecimal%';"
ECHO %ipdecimal%>%serverpath%\Batch_Files\ip_decimal.txt
cls
ECHO.
ECHO.
ECHO Public IP address is new. Please restart the DSP server.
pause
:end
1. Extract the batch files from the zip file to anywhere you want.
2. Right click on the batch file Update_ZoneIP_with_server_reboot_v1.1.bat and select "edit" to open it in notepad (you can use any text editor you want)
3. Under the heading "::Set Variables", change each of the values to what you need. There are descriptions in the batch file for what each one is.
4. If you don't want the batch file to run in a loop doing a constant check of the IP, then comment out "goto start" at the end of the batch file by adding "::" in front of it. So it should look like this ::goto start
5. Save and run the batch file and that's it you're done. From now on all you have to do is double click that batch file and it will run constantly in a command prompt window and update your zoneip_settings sql table when your public IP address changes and reboot your DSP server automatically. To double check to make sure it changed the zoneip just open up the zone_settings table in your mysql database and it should have a different value for the zoneip field.
Code: Select all
echo off
::***************************************
::* *
::* ZoneIP Update Script v1.1 *
::* By Kloe *
::* *
::***************************************
::Set Variables
::=============
::DSP server root path. Example: C:\DSP
set serverpath="PATH_TO_DSP_ROOT"
::Dynamic DNS Hostname. Example: darkstarproject.dyndns.org
set ddnshost=YOUR_DDNS_HOSTNAME
::mysql host address
set dbhost=localhost
::mysql database username
set dbuser=root
::mysql database password
set dbpass=DB_PASSWORD
::mysql database name
set dbname=DB_NAME
cls
:start
::Creates a folder for storing output files if it does not exist
::==============================================================
if not exist %serverpath%\Batch_Files md %serverpath%\Batch_Files
::Extract IP Octects from nslookup of Dynamic DNS Hostname
::========================================================
for /f "tokens=5 delims=:." %%i in ('nslookup %ddnshost% ^| findstr /C:"Address:"') do set a=%%i
for /f "tokens=4 delims=:." %%j in ('nslookup %ddnshost% ^| findstr /C:"Address:"') do set b=%%j
for /f "tokens=3 delims=:." %%k in ('nslookup %ddnshost% ^| findstr /C:"Address:"') do set c=%%k
for /f "tokens=2 delims=:." %%l in ('nslookup %ddnshost% ^| findstr /C:"Address:"') do set d=%%l
cls
::Convert Octets to Decimal
::=========================
::Octet Format Example: address 192.168.1.1 would be read in reverse order (1.1.168.192)
::So octet1 is 1, octet2 is 1, octet3 is 168, and octet4 is 192
set /a octet1=%a%*(256*256*256)
set /a octet2=%b%*(256*256)
set /a octet3=%c%*256
set /a octet4=%d%*1
set /a ipdecimal=%octet1%+%octet2%+%octet3%+%octet4%
::If file storing old IP Decimal value exists go to ipcheck otherwise go to ipexport
::==================================================================================
if exist %serverpath%\Batch_Files\ip_decimal.txt goto ipcheck
goto ipexport
:ipcheck
::Check to see if %ipdecimal% has changed to see if your public IP has changed
::===============================================================================
set /P oldip=<%serverpath%\Batch_Files\ip_decimal.txt
if %oldip% == %ipdecimal% (
cls
ECHO.
ECHO.
ECHO IP address Hasn't Changed.
::pause
goto end
)
goto ipexport
:ipexport
::Run a Query that updates the zoneip field in the table "zone_settings" to update the IP address in sql
mysql -h %dbhost% -u %dbuser% -p%dbpass% %dbname% -e "UPDATE zone_settings SET zoneip = '%ipdecimal%';"
ECHO %ipdecimal%>%serverpath%\Batch_Files\ip_decimal.txt
cls
ECHO.
ECHO.
ECHO Public IP address is new. Restarting DSP Server...
::Kill server processes to shutdown server
taskkill /IM DSConnect-server.exe /F
taskkill /IM DSGame-server.exe /F
taskkill /IM DSSearch-server.exe /F
::Startup the Connect, Game and Search Server
::===========================================
start "DSP Connect Server" /D%serverpath% "%serverpath%\DSConnect-server.exe"
start "DSP Game Server" /D%serverpath% "%serverpath%\DSGame-server.exe"
start "DSP Search Server" /D%serverpath% "%serverpath%\DSSearch-server.exe"
::pause
:end
goto start