Script to get computer name based on IP Address

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
tbharber
Posts: 32
Joined: 17 Sep 2010 17:08

Script to get computer name based on IP Address

#1 Post by tbharber » 20 Sep 2010 13:16

I am working to create a script that you can type in a computer name on the network and it will give you the IP Address. Also if you enter the IP Address it will give you the computer name. There are several commands that will do this such as NSLOOKUP and NBTSTAT but they list a bunch more data than just the IPAddress/computer name .

ex.
set /p compname=Enter Computer Name:
NBTSTAT -a %compname%| Find "IpAddress:"
echo %compname%

This displays:"Node IpAddress: [10.17.194.59] Scope Id: []"

I am looking for a way so just the computer name/IP Address get listed at the end without all of the other data.

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Script to get computer name based on IP Address

#2 Post by aGerman » 20 Sep 2010 14:06

Use FOR /F to process the output.

Code: Select all

for /f "tokens=2 delims=[]" %%a in ('nbtstat -a %compname%^|find "IpAddress:"') do echo %compname%/%%a


Regards
aGerman

Post Reply