Detect if computer on local domain is reachable

rbichon
rbichon used Ask the Experts™
on
I am able to enumerate all of the computers on my domain using LDAP and wscript. Now what I would like to do is determine which ones are currently powered on/reachable over the network. I would use ping except that it does not give reliable results. For example, if one of the domain members is using DHCP, sometimes the IP address is different on the machine than it is in DNS. Any help would be most appreciated. Thanks.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
Ummm..   If the machine name and IP don't match what's in DNS, then there is no reliable way of talking to the computer, not for you, or for the domain.  I would adjust your scavenging settings...

HTH,
exx

Author

Commented:
Good idea.
"if one of the domain members is using DHCP, sometimes the IP address is different on the machine than it is in DNS."

This should never be the case in a good network design.

Become a Certified Penetration Testing Engineer

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

Author

Commented:
Well, one thing that happens is that a laptop is assigned an IP address by the router and then is shutdown or removed from the network for a long period of time. Then, another computer/laptop is assigned the same IP in a later date. It seems that our DNS server does not delete the original entry for that IP when another computer takes it over. Any ideas as to why this happens? Should I avoid using the routers DHCP function and setup DHCP on our main server?
If you have a Domain Controller and use it for DNS then yes you should probably be using DHCP from the server as well, and you now see why :).
Commented:
Yes, you should always be using windows DHCP if you are in an AD environment and running windows DNS.  That change, in addition to adjusting scavenging, will fix those issues for you, and then you can look up hosts through DNS to get proper name resolution and figure out which ones are still on the network.

Author

Commented:
I have two GC servers on my domain, both running DNS. Does it matter which one I use for DHCP?  Also, will this prevent others from obtaining an IP via DHCP who connect to the lan/wlan without being on the domain, i.e. customers, vendors, etc?

Commented:
You can use either, and no, DHCP is a network protocol, like DNS.  It doesn't require authentication.  It will hand out addresses to whatever is configured for DHCP.  PCs, printers, whatever.

HTH,
exx
Quick addition, the only problem would be if the DHCP server goes down you would have a problem, so it would be good to build in redundancy with your servers or you would need to reconfigure the routers to supply DHCP in such a situation.

Commented:
Or just make the DHCP lease like 7 days..  Then you have at least 3.5 days to fix it or build a new one..
For the existing computers maybe but it wouldn't help if a customer/vendor laptop came into the network.

Commented:
And in those one-off situations, a static IP works quite well.

Redundant DHCP is a good idea, but it can quickly become an administrative nightmare.  If he was using a router for DHCP, I'm going to take a flyer and say that

A) there was no redundancy before

and

B) the network is probably not of a size that requires that level of complexity.


Just my $.02, YMMV.

-exx

Author

Commented:
I am using the secondary DNS server to act as the DHCP server. Also, my router had three settings in regards to DHCP; 1) DHCP Enabled, 2) DHCP Disabled, 3) DHCP Relay. I am using DHCP relay and have plugged in the IP of the server that it relays to. I don't know if this is necessary, but everything switched over fine with no problems.
Now, back to my original question. I created a vbscript that queries each domain member to see if it is active and reachable by the domain. It is slow but effective.

On Error Resume Next
set sh = createobject("wscript.shell")
Set fso = CreateObject("Scripting.FileSystemObject")
Set sys32 = fso.GetSpecialFolder(1)
'********************************************************************************************************************************************

Set ObjOU = GetObject("LDAP://CN=Computers,DC=mydomain,DC=local")
For Each objMember in ObjOU.Member
	Set ObjComp = GetObject("LDAP://" & objMember)
	Set Processes = GetObject("winmgmts://" & ObjComp.CN).ExecQuery("select * from Win32_Process")
	if (err.number = 0) then
		'Server connected successfully to the remote computer
		sh.run sys32 & "\shutdown.exe /r /f /m \\" & ObjComp.CN & " /t 300 /c " & chr(34) & "Domain: System Reboot" & chr(34),0
	end if
	err.clear
Next

Open in new window

Commented:
DHCP relay is only necessary if the DHCP Server will be handing out addresses to networks other than the one it is on.

For example, if the server is on 192.168.1.0/24, and the PCs are on 192.168.2.0/24, then yes, you'd have to configure your router or layer 3 switch with DHCP forwarding (called IP-Helper in Cisco gear).

Glad you got it worked out.


-exx

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial