Glen Morse
Glen Morse

Reputation: 2593

Check domain of another computer on the network

I have two PC's, pcA and pcB. I need to run a batch file on pcA to check if pcB is on the correct Domain (EEP202) If if it is, it should return PASS if not it should return FAIL.

I am not too good with networking, but I am guessing that I could first ping pcB. If it does not pass then its definitely not on the correct domain.

If it does pass then I assume you can pull the domain from the ping?

Any help would be great!

Upvotes: 0

Views: 1875

Answers (1)

craig65535
craig65535

Reputation: 3572

Assuming you're talking about the Windows domain, you can use nbtstat to query a computer's name, domain and some other properties:

nbtstat -A x.x.x.x

Here's a link from Microsoft with an explanation of the options and output format.

If you want the domain specifically, you can use:

nbtstat -A x.x.x.x | find "<00>" | find "GROUP"

Ping will not return what domain a computer is joined to.

You can get 0 or 1 for the domain eep202 with this single line:

nbtstat -A x.x.x.x | find "<00>" | find "GROUP" | find /c /i "eep202"

If you really want to only echo "pass" on success then you'll need to write a batch file. Let's call it verify_eep202.bat:

@echo off
for /f "delims=" %%a in ('nbtstat -A %1 ^| find "<00>" ^| find "GROUP" ^| find /c /i "eep202"') do set found=%%a
if %found%==1 echo pass

You can then run verify_eep202.bat x.x.x.x

Upvotes: 1

Related Questions