How can my my batch file determine whether I'm on my work network?

A generic approach to check for specific network characterisics, e.g. a specific IP-Address, aber given server IP or the output of a traceroute. For this to work, it is important to know the differences in the network topologies and exploit them. A more detailed explaination would required some more information on the problem setting.


I could ping our domain controller and check for an error:

ping -n 1 servername
if errorlevel 1 exit

The downside is that I have to wait for a timeout when it doesn't work. I was hoping for something immediate. I'm open to better suggestions.


I could check whether the default gateway is set for work:

ipconfig | find "10.1.1.1"
if errorlevel 1 exit

At a command prompt enter echo %logonserver% and see if your domain computer is returned as the server that you are connected to.

In fact, here is an even better way, put this in your bat file....

@echo off 
IF EXIST %logonserver% (
  echo 'On LAN!'
)ELSE (
  echo 'Not on LAN!'
)

Hope that helps. if you know the authentication server name you can obviously add a conditional equal statement in the if portion to confirm that the server exists, then run the remainder of your batch file. And of course the ELSE portion would simply exit.