Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am writing a Powershell script to determine if a machine is on the corporate network. The machine may or may not be on the domain, so I want to check at "IP" level.

Have written something to check by pinging a couple of servers on a couple of different subnets (to get around the risk of someone being on another (external) subnet with a host on the same IP.)

Works, but it's a bit slow, and not especially "future-proof" - e.g. in 2 years time when I decomission the server it'll break.

Is there a way I can use the dns suffix being given by the local dhcp server?

Just direct me what I need to check - I can figure out the script.



share|improve this question
There's no possibility that you'll be able to ping a host on a different subnet with the same ip address as a host on your subnet, so banish that thought from your head. – joeqwerty May 25 '10 at 20:44
up vote 3 down vote accepted

Look into WMI. The Win32_NetworkAdapterConfiguration class will tell you information about the host like what dns suffix it has and from which DHCP server it leased an ip address.

share|improve this answer
Worked a treat! Thanks – Ben May 25 '10 at 21:15

Hmm, interesting problem...

My $3.50: Create a DNS entry (like IN A on your inside DNS with a 1-second TTL & try to resolve it.

If it exists (& matches the IP it should be) then you're on the internal network. If not you're somewhere else. (Note that this has a bunch of problems too, but it seems a little better than the ping-around-the-network method).

share|improve this answer

Perhaps the simplest method is to look for certain things that should always be available on the LAN. e.g. The gateway machine and a DNS query for something that only the local DNS server should be able to answer.

share|improve this answer

Maybe not exactly what you want but it might get you there.


share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.