Home > Technology > Know DHCP IP of your headless Windows Box!

Know DHCP IP of your headless Windows Box!

A headless system is something which don’t have a monitor connected to it, or neither have a remote access console. Usually such systems are assigned statically configured IPs so that the IP don’t change over machine reboots and hence the system don’t lose access. But what do you do when you have a headless system in a network where the IPs are assigned through DHCP. If the system is not often booted often, then its fine. Again, DHCP keeps the lease for some days or even up to weeks and you end up getting the same IP even over multiple reboots. But consider a case where you are in a busy network, where people connects multiple devices to the network and IPs are leased through DHCP. You may lose the IP even in the next reboot. So, a headless system is a big pain in the arse.

If you are using a UNIX/Linux system, you are lucky. Just write a simple shell script where you get your current IP address and mail it through sendmail or other email utilities through your SMTP server. You can include this script in your rc scripts which gets executed during system startup and you conveniently get an email in your inbox with the IP address of your headless workstation. Life is simple in the UNIX/Linux world for these tasks. But, what do you do when you have a headless Windows box? We can do something similar. Lets see.

A major part of the following content is attributed to the following blog post:


1. Download SendMail for Windows.

2. Put the following content into a Windows Batch file, say ip.bat:

ipconfig > ipaddress.txt
SendEmail.exe -f FROMADRESS -t TOADDRESS -u SUBJECT -m MESSAGE -s SMTPSERVER -a ipaddress.txt

Now, if you link the above script to Start Menu\Startup, our problem is not solved fully. Because mostly the programs specified under Start Menu\Startup is executed after user logon. But if you don’t know the IP address of the system, you can’t connect and so you cant login. So, we are no good with this. At this point, you can do two things, or may be more. I am aware of just Two 🙂

1. Create a task using task scheduler, to run the task at system startup and link ip.bat as the program which should run every time this task is executed. Pretty straight forward. You can go to Task Scheduler from Administrative Tools menu in Windows 7.

2. Include ip.bat under startup scripts using the group policy editor.

execute gpedit.msc, go to Local Computer Policy -> Computer Configuration -> Windows Settings -> Scripts (Startup/Shutdown)

Startup -> Right Click (Properties) -> Add your script ip.bat

Be careful about the paths etc. in your script, you are done!

But, frankly you are not fully done here. There is a catch. It might so happen that by the time your script ip.bat gets executed as a part of the startup scripts , your network configuration may not have completed, so you might get an email with incomplete ipconfig data. To get around of this issue, just sleep for some time before you ipconfig is executed in ip.bat. May be 15 – 20 seconds by using timeout command. But, by default, the startup scripts are executed in order and so waiting for 15 – 20 seconds may increase your boot time significantly. So avoid such an issue, we can execute the startup scripts asynchronously.

Just enable a policy, again using gpedit.msc

Enable Local Computer Policy -> Computer Configuration -> Administrative Templates -> System -> Scripts -> Run startup scripts asynchronously


Categories: Technology
  1. No comments yet.
  1. No trackbacks yet.

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 )

Google+ photo

You are commenting using your Google+ 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 )

Connecting to %s

%d bloggers like this: