If your modem/router has support to UPNP reconnect, it's easy to create a reconnect script.
Test it running the .class file in attachment, and post the result when you ask for help for a script to reconnect.
Linux:
run the file
run_linux.sh
Windows:
run the file
run_windows.bat