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