Ping Service by Glenn Delahoy (C) Copyright 2003 All rights reserved Description ----------- This tool provides a method for monitoring the state and ip of a machine on the network. The scenario goes like this: I have a machine which provides some kind of remote service across the internet. However the machine is connected to the internet via cable/adsl or some other kind of non-permanent connection. The result is the ip is unreliable and can change at the whim of the isp. This means at any point in time I can't guarantee what the ip of my machine is so when I attempt to use my service from a remote location it may or may not work. Additionally, once the ip has changed I have no way of knowing what the new ip is. This tool solves the problem by using a third party machine which does have a reliable ip to monitor the first machine via the ping protocol. This third party monitor machine records regular pings coming from the first machine and notes when the ip changes. When you can no longer access your machine remotely and suspect the ip has changed, you telnet into the third party machine and examine the ping log to discover the new ip. To set up this monitoring tool you install a service on the machine that needs to be monitored. You tell it who to send pings to, on which port and how long between each ping. Then you install a service on the third party monitoring machine which listens for the pings on the given port. You also tell it on which port to listen for incoming telnet connections. Installing the Ping Service --------------------------- On the first machine, edit the PingService.reg file. Set the host key to the ip address of the third party monitoring machine. The port is set by default to 16668. You can change it or leave it, this port is not used by any program I know of. Set the Secs key to the time in seconds between each ping. This is set to 5 seconds by default. You can change it or leave it. The Id key identifies the machine to the listener and is recorded in its cache so you can match the machine name to the ip. You can make this anything you like up to ten characters to uniquely identify the machine. To switch on debug mode, set the Debug key to 1. This creates a log file in the root directory of your C: drive. Save the reg file and double click it from Explorer to install the keys into the registry. Open a command prompt and change to the directory containing the PingService.exe. Type the following command: pingservice /install This installs the program as a Windows service. Now open the Windows Services module and start the service. All going well, the service will commence sending pings to the third party machine. Installing the Ping Listener Service ------------------------------------ On the third party monitoring machine, edit the PingListener.reg file. Set the PingPort key to the same port as set in the other reg file. This is set to 16668 by default. Set the TelnetPort key to any suitable port for accepting incoming telnet connections. This is set to 16669 by default. This port is not used by any other programs I know of. Set the CacheSize to adjust the size of the ping history stored in memory. This is set to 1000 lines by default. You can adjust this as desired. To switch on debug mode, set the Debug key to 1. This creates a log file in the root directory of your C: drive. Save the reg file and double click it from Explorer to install the keys into the registry. Open a command prompt and change to the directory containing the PingListenerService.exe. Type the following command: pinglistenerservice /install This installs the program as a Windows service. Now open the Windows Service module and start the service. All going well, the service will now be listening and recording the pings coming in on the given port. Remotely Accessing the Listener ------------------------------- With the ping listener running you can now telnet into it by typing the following command at the Windows command prompt: telnet You'll see the Ping Listener banner and a login prompt. In order to log in, the listener needs to have a user set up. To set up users you need to add keys to the registry. Open the registry editor and go to: HKEY_LOCAL_MACHINE\SOFTWARE\PingService\PingListener Add a new key called users. Below this add new keys for each user. The 'default' value for each user is the password. You do not need to restart the service for these changes to have effect. You can now log in to the listener. Once logged in you'll see a few lines of information followed by the list of commands. MONITOR This displays the incoming pings as they happen. You can leave this running as a monitor if you like. To stop the monitor type MONITOR OFF. CACHE Displays every recent ping recorded. The length of this cache is set by the CacheSize registry key. Once an entry scrolls off this list it is gone. LAST Displays the last entry for each Id received. This is a quick way to view the latest ip for each machine being monitored. These entries are stored in the registry. Every time an Id changes its ip, an entry is created in the registry. HISTORY Displays the ip change history for the given Id as recorded in the registry. To view the history for a given Id type HISTORY where is the identifier of the machine you wish to view. To view the history of all Ids, type HISTORY without any parameters. INFO Displays the list of available commands. HELP Displays the list of available commands. QUIT Closes the telnet session. ------------------------------------------------------------ Comments/suggestions to: support@delahoy.com http://www.glenn.delahoy.com