China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-05 11:21
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » How do I modify a batch file to use an IP to look up the machine name? View 746 Replies 1
Original Poster Posted 2007-07-07 16:08 ·  中国 陕西 西安 电信
初级用户
Credits 51
Posts 26
Joined 2007-05-13 15:08
19-year member
UID 88407
Gender Male
Status Offline
I want to use the batch file below to enter an IP address and get the machine name. The code is as follows, but it doesn't give the expected result.
@echo off
set b=
set/p b=Please enter the IP address:
for /f "skip=8 tokens=1 delims= " %%i in ('nbtstat -a %b%') do echo The machine name for %b% is: %%i
pause>nul


When I enter 192.168.0.1, I get:
Please enter the IP address:192.168.0.1
The machine name for 192.168.0.1 is: PC6
The machine name for 192.168.0.1 is: PC6
The machine name for 192.168.0.1 is: WORKGROUP
The machine name for 192.168.0.1 is: WORKGROUP
The machine name for 92.168.0.1 is:
The machine name for 192.168.0.1 is: MAC
The machine name for 92.168.0.1 is:
The machine name for 192.168.0.1 is: 11:
The machine name for 192.168.0.1 is: Node
The machine name for 92.168.0.1 is:
The machine name for 192.168.0.1 is: Host


How can I make it return only the machine name?
If I want to add a line like: The workgroup the machine belongs to is: then how do I do it? Thanks.
Floor 2 Posted 2007-07-13 11:57 ·  中国 江苏 苏州 电信
初级用户
Credits 24
Posts 11
Joined 2007-07-13 10:36
19-year member
UID 93864
Gender Male
Status Offline
@echo off
set b=
set/p b=Please enter the IP address:
for /f "tokens=1 delims= " %%i in ('nbtstat -a %b%^|find "<20>"') do echo The machine name for %b% is: %%i
set

This should be your program with a small modification.
Forum Jump: