DULMEN.net   Follow me on Facebook Contact DULMEN.net  

SwitchHosts - Programming@DULMEN.net

SwitchHosts
Tool to switch the Windows HOSTS file for VPN connections using IP translation. It can hold several HOSTS settings which can be switched from the system tray by clicking the SwitchHosts icon.
 
Features
-Switch between 2 or more HOSTS configurations
-Open VPN connection program when HOSTS configuration changes
-Optionally keeps your Windows session unlocked
-Application hides in the Windows system tray
 
Description
Due to company policy the VPN tunnels to customers for remote support changed. This had big influence on the way the on-site engineers connect to the customers servers and devices during remote support from home in the weekends.
With the old VPN between the company and the customer the on-site engineers could connect to their company and use the VPN tunnel to the customer. For accessing the servers, automation and devices the same IP addresses could be used as being on-site.
The new VPN tunnel to the customer uses double NAT (Network Address Translation). That is why for remote support a different range of IP addresses is used as opposed to being on-site at the customer.

One way of dealing with this situation was reconfiguring all tools and programs on the engineers laptop every time he switched between being remote or on-site. Another solution would be accessing the customers network using hostnames but the lack of a DNS server prohibited this option. But there is a way that allows the use of hostnames even without a DNS server: the Windows HOSTS file. The Windows HOSTS file is a list with IP addresses with their hostnames and can be found in the folder c:\Windows\System32\Drivers\Etc. Only downside is that whenever the situation changes (on-site/remote) the HOSTS file needs to be changed. This system tray application does the trick in no time.

Just choose the setting you need from the SwitchHosts system tray menu and the corresponding HOSTS file will be copied to the c:\Windows\System32\Drivers\Etc folder, overwriting the old HOSTS file.
As from version 1.1 SwitchHosts can also popup the VPN connection whenever a different HOSTS file is selected. In version 1.2 an option is added to keep Windows unlocked/awake not to loose the VPN connection.

The first time SwitchHosts is started it elevates itself by registering with the highest privileges. The Windows User Account Control (UAC) will prompt for confirmation. As long as it is started from the same folder this confirmation is not needed after the first run.
 
Screenshots
SwitchHosts about box and system tray menu
 
Commandline options
No command-line options available.
 
Configuration file settings
[NoSleep]
NoSleep Keep Windows session active (1 = Enablede, 0 = Disabled)
DelayTime Number of seconds between mouse moves (0 ... 300)
[VPNclient]
WindowTitle Title of the VPN connection program
ProgramExe Full path to the VPN connection program
 
HOSTS file examples
#Onsite

# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost

# EXAMPLE HOW TO SETUP YOUR HOSTS FILES
# YOU CAN ADD AS MANY ROWS AS YOU NEED

10.163.60.36 DBSERVER1
#172.19.11.24 DBSERVER1

10.163.60.37 DBSERVER2
#172.19.11.25 DBSERVER2
 
#VPN

# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost

# EXAMPLE HOW TO SETUP YOUR HOSTS FILES
# YOU CAN ADD AS MANY ROWS AS YOU NEED

#10.163.60.36 DBSERVER1
172.19.11.24 DBSERVER1

#10.163.60.37 DBSERVER2
172.19.11.25 DBSERVER2
 
The # options out a row. Hostname DBSERVER1 in the first example is IP address 10.163.60.36 and in the second example 172.19.11.24.
Make sure to put a unique name in the first row for the HOSTS files preceded with a #. This will result in Windows ignoring the first row and SwitchHosts to recognize the file and to display the name in its system tray menu.
Save your HOSTS files using the same name as set in the first row in the folder "\SwitchHosts\hosts" with the extension ".hst". In the above example this would be "\SwitchHosts\hosts\Onsite.hst" and "\SwitchHosts\hosts\VPN.hst".
 
Version history
v1.0 Initial setup
v1.1 HOSTS file configurations in SwitchHosts sub folder
Added starting VPN connection program popping up if HOSTS configuration is changed
v1.2 Added "No Sleep" option
 
Known bugs
No known bugs.
 
Future enhancements
None.
 
Download
Please read the legal notice first, allthough you probably heard it before :)


Copyright 2018 DULMEN.net. All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY DULMEN.net ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL DULMEN.net OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

The views and conclusions contained in the software and documentation are those of the authors and should not be interpreted as representing official policies, either expressed or implied, of DULMEN.net.


You can download SwitchHosts as a compressed folder containing all files needed. No need to install the software, just unzip, adapt the configuration file SwitchHosts.ini and run SwitchHosts.exe.
SwitchHosts is free for personal and bussiness use and is free to distribute as is as long as the program is not altered and accompanied with the SwitchHosts text file.

VersionFileSize
v1.2SwitchHosts_v1.2.zip425,55 KB (435764 bytes)
v1.2SwitchHosts_v1.2.7z350,4 KB (358806 bytes)
v1.1SwitchHosts_v1.1.zip350,47 KB (358886 bytes)
v1.1SwitchHosts_v1.1.7z346,53 KB (354851 bytes)
 
 
DULMEN.net © v8 2018 - Designed & written by Arno van Dulmen