Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

Ta,

Ben

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

4 Answers 4

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 hey.look.im.on.the.internal.network.mycompany.com. IN A 127.0.0.1) 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.

Script

share|improve this answer

Your Answer

 
discard

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.