Update ZoneIP Settings w/DDNS IP v1.1 (Updated 12/17/13)

Applications/Tools written to make running DarkStar easier for the rest of us.
Post Reply
kloe
Posts: 11
Joined: Fri Dec 06, 2013 10:13 pm

Update ZoneIP Settings w/DDNS IP v1.1 (Updated 12/17/13)

Post by kloe » Sun Dec 15, 2013 12:39 am

Hello everyone, I have come up with a batch file that will do an nslookup of your dynamic dns host name, convert the IP address to decimal format, then update the zoneip field in the sql table "zone_settings". So now everytime your IP changes you just need to double click on the batch file (after you configure it properly) and bam! Your zoneip settings will be changed to your new IP address! This will allow you to give out a hostname to poeple that connect to your server so they won't ever have to change it in their ashita client (the ffxi-boot that uses an ini config file does not support hostnames).

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:
- 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.
Virus Total Scan:
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
Setup Instructions For 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_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
If you have any issues or suggestions on additional feature or tweaks don't hesitate to tell me. :)
Attachments
Update_ZoneIP_v1.1.zip
(2.37 KiB) Downloaded 280 times
Last edited by kloe on Sun Dec 22, 2013 11:37 am, edited 4 times in total.

User avatar
tagban
Posts: 352
Joined: Fri Dec 28, 2012 11:31 am
Location: Pennsylvania, USA

Re: Update ZoneIP Settings With Dynamic DNS IP Change Batch

Post by tagban » Mon Dec 16, 2013 5:10 am

Looks great, the new FFXI Boot does actually support host names though. At least, works fine with mine.

kloe
Posts: 11
Joined: Fri Dec 06, 2013 10:13 pm

Re: Update ZoneIP Settings With Dynamic DNS IP Change Batch

Post by kloe » Mon Dec 16, 2013 10:07 am

Oh the FFXI-Boot I was referring to was the one that uses the .ini file for it's config.

spiko
Posts: 1
Joined: Wed Mar 20, 2013 4:38 pm

Re: Update ZoneIP Settings w/DDNS IP v1.1 (Updated 12/17/13)

Post by spiko » Tue Apr 15, 2014 12:20 pm

please help me, my ipdecimal show negative numbers how can i fix this?

Post Reply