Page Last Updated: 21/02/2010 Location Detection
|
This information was originally on our community
site amset.info, and you may have been
redirected to this site by following a link to a URL
on that domain. This is the same information, from
the same source, just in a new location.
|
If you have a single domain spread over many sites it can be useful to be able to detect where the machine is and then connect it to the local printer or network shares. This is especially useful if you have roaming users who move between offices.
If you have a static environment and can control the naming convention then there is an alternative solution which may work better for you. More Information.
One method that works it to use the default gateway of the machine to detect where the machine is located. You must have different IP address ranges in each site for this to work correctly. Below is an example script with notes so that you can adjust how it for your own environment.
Note: Numbers in the notes correspond with the numbers down the side of the example script.
- For reference, the two subnet addresses being searched are contained at the top of the script. Useful when updating the original.
- The script carries out the command "ipconfig" and dumps the result in a text file in the user's profile directory. This also has the side effect of verifying the last time the login script was run correctly by the create date on the file.
- Short echo so the user knows something is going on.
- Searching for the first gateway address - the UK. If found it will be sent to the UK section further along the script. If it fails, it moves along to the next gateway. The "findstr" command is native file on Windows 2000 and XP.
- Now searching for the US gateway address. If this one fails, it goes to another place in the script, but it could easily search a forth gateway address.
- The sections called earlier. You could in here call separate scripts instead of commands, thus reducing the size of this initial script.
Remember to put in a "goto" command to skip the rest of the location based information. Otherwise the script will just continue moving down and will execute the next set of commands as well.
| 1. |
rem Subnets for reference rem UK subnet: 192.168.22.254 rem US subnet: 192.168.11.254 |
| 2. |
rem Grab IP address and dump to a file ipconfig >"%userprofile%\ipconfig.txt" |
| 3. |
echo Checking for your location |
| 4. |
rem Seaching for default gateway in IP dump above findstr "192.168.22.254" "%userprofile%\ipconfig.txt" if not errorlevel 1 goto UK echo Not UK goto next |
| 5. |
:next findstr "192.168.11.254" "%userprofile%\ipconfig.txt" if not errorlevel 1 goto US echo not US goto other |
| 6. |
:UK rem UK settings goto :next
:US rem US settings goto :next
:other rem Other settings (for VPN etc) goto :next
:next
rem more commands
:end |
Complete Sample - Ready to Copy and Paste.
Remember to turn off word wrap when working in notepad
About this site
This information originally started life as a page on amset.info, our community assistance site. However that site is targeted at Microsoft Exchange server, as Sembee Ltd. is a Microsoft Exchange consultancy. Therefore it was moved to its own domain in early 2010. Traffic from amset.info is directed here.
Other sites that are owned and operated by Sembee Ltd include kbsearch.info, certificatesforexchange.com, dosprompt.info, office-recovery.info, wuauclt.info, blog.sembee.co.uk, exbpa.com and amset.info.
|