1

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

Ben
  • 1,137
  • 9
  • 26
  • 44
  • 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 Answers4

3

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.

AdamW
  • 236
  • 2
  • 7
2

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).

voretaq7
  • 79,879
  • 17
  • 130
  • 214
1

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.

John Gardeniers
  • 27,458
  • 12
  • 55
  • 109
1

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

Script