Remote IP Discovery

1 03 2010

The need

Occasionally I need to access a computer using remote desktop, however the IP address of the computer is dynamic and changes every few weeks making the computer unreachable via remote desktop.

Here I describe how I setup a couple of simple batch files that will record the computers IP address to a secure website. More importantly the website can be used to trigger a new IP discovery on the remote computer. Oh yeah, it’s all for free :-)

Outline

  • Install DropBox webservice in order to store the IP address of the computer(s) you wish to interrogate.
  • Install two batch files on the target PC’s one which run in the scheduled tasks manager in windows.
  • Create a ‘trigger’ text file on the target PC.
  • Rename the trigger file to a given name to initiate the interrogation and publishing of the IP address.

Step 1 – Install DropBox

Install Dropbox on the PC you wish to have publish its IP address and setup a free 2GB account with them. When installing DropBox be sure to specify the location of your dropbox folder as c:\My DropBox

Install DropBox on other computers you would like to trigger the IP Discovery from.

Dropbox can be downloaded here. This gives you 2GB of free web based file storage that can be synchronized between one or more computers. Dropbox is a great service, explore their demos, you may find yourself using this for more than this simple exercise.

Click to enlarge

Step 2 – Install 2 simple batch files

Make a folder on your c drive called c:\batch

In this folder place two batch files called ObtainIpAddress.bat and RenameTriggerFile.bat.

ObtainIpAddress.bat should contain the following.

if not exist "c:\my dropbox\getip-wait.txt" goto end.
ipconfig/all > "c:\my dropbox\work-ipaddress.txt"
cd "c:\my dropbox"
rename getip-go.txt getip-wait.txt
:end

RenameTriggerFile.bat should contain cd “c:\my dropbox”

if not exist "c:\my dropbox\getip-wait.txt" goto end.
cd "c:\my dropbox"
rename getip-wait.txt getip-go.txt
:end

Launch the windows schedule tasks applet (Start, Control Panel, Scheduled Tasks).

Create a new scheduled task that will run the c:\batch\ObtainIpAddress.bat file every 5 minutes.

Click to Enlarge

Create another new scheduled task that will run the c:\batch\RenameTrigger.bat file once per week.

Click to Enlarge

Step 3 – Create a trigger file in your dropbox folder.

Create a file in you My DropBox folder called getip-wait.txt. It can contain any text you wish, or be blank.

Obtaining the remote IP Address

At any time you wish to know the IP address of the remote computer simply rename the trigger file in My DropBox from getip-wait.txt to getip-go.txt. This can be done on the dropbox website once you have authenticated to your account or by renaming the file on a second computer. The remote computer will see the file and place the IP address information of the remote computer in your dropbox in a file called work-ipaddress.txt.

Note that the weekly run of RenameTriggerFile.bat will automatically trigger the discovery of the IP address.

Fine Tuning

The ObtainIpAddress task that runs every 5 minutes may annoy since a window will appear momentarily on the screen. One can adjust the scheduled run time of the task to run only when you are scheduled to be away from the computer or when the computer is idle for a given time period.

Sample Schedule 1 – Monday – Thursday

Click to Enlarge

Sample Schedule 2 – Weekend

Click to Enlarge

Sample Schedule 3 – Friday

Click to Enlarge

Dropbox is intelligent and will only change the file on your DropBox account if the file contents change.

Sample Output

The file created by this procedure is as follows:-

Windows IP Configuration

Host Name . . . . . . . . . . . . : xxxx
Primary Dns Suffix  . . . . . . . : xxxxx.xxx
Node Type . . . . . . . . . . . . : Hybrid
IP Routing Enabled. . . . . . . . : No
WINS Proxy Enabled. . . . . . . . : No
DNS Suffix Search List. . . . . . : xxxx.xxx

Ethernet adapter Local Area Connection:
Connection-specific DNS Suffix  . : xxxxxx.xxx
Description . . . . . . . . . . . : Broadcom NetLink (TM) Gigabit Ethernet
Physical Address. . . . . . . . . : xx-xx-xx-xx-xx-xx
Dhcp Enabled. . . . . . . . . . . : Yes
Autoconfiguration Enabled . . . . : Yes
IP Address. . . . . . . . . . . . : 192.168.x.x
Subnet Mask . . . . . . . . . . . : 255.255.x.x
Default Gateway . . . . . . . . . : 192.168.x.x
DHCP Server . . . . . . . . . . . : 192.168.x.x
DNS Servers . . . . . . . . . . . : 192.168.x.x
xx.xx.xx..xx
xx.xx.xx..xx
Primary WINS Server . . . . . . . : 192.168.x.x
Secondary WINS Server . . . . . . : 192.168.x.x
Lease Obtained. . . . . . . . . . : Sunday, February 28, 2010 8:25:48 AM
Lease Expires . . . . . . . . . . : Monday, March 08, 2010 8:25:48 AM
Advertisements

Actions

Information

3 responses

17 10 2012
Nate

This only finds your private IP address. If you are behind a router, like 99% of people are, your IP address is going to be 192.168.1.XXX… You want to find your Public IP address.

Bad Tutorial.

17 10 2012
jpwhitehome

For the purposes of what I wanted to do I did actually want the private IP address. My companies public IP address is static and known and of no value to me.

It’s a question of what you want to do. I’m simply sharing what I did; Works fine for me :-)

17 10 2012
Nate

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




%d bloggers like this: