Solved Please help me with Batch, need manual input required see description

lewisaro

New member
Local time
8:16 AM
Messages
7
Hi there,
I am trying to create a batch file which will use the command nbtstat-a and then request the IP of the user within the same line (e.g. nbtstat-a *please enter the target IP to lookup*) to look up the machine name of a computer on the network, the only problem is that i dont know how to make it so that the first part is automatically filled out (nbtstat -a) then the user has to input the IP address to continue.
Please could anyone help?
Thanks :) Much Appreciated
 

My Computer

Computer type
PC/Desktop
OS
windows 7 pro 64bit
CPU
Intel 3570k
Motherboard
asus maximus v gene
Memory
12GB
Graphics Card(s)
gtx 660
Hard Drives
2x 1TB WD
1x SSD
Antivirus
avast
Browser
icedragon
Hi,

Welcome to Seven Forums

To concatenate commands use the & symbol.

For example, Command A & Command B

Try this.

set /p id="Enter IP Address: " & nbtstat -a %id%

Tanya
 

My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Home Made
OS
Linux Mint 17 Cinnamon | Win 7 Ult x64
CPU
Intel I7-3770K @ 4.2ghz
Motherboard
ASRock Extreme 4
Memory
32GB G-Skill C10Q
Graphics Card(s)
EVGA GTX 670 2GB SC
Sound Card
Creative Fatality ExtremeGamer
Monitor(s) Displays
LG E2742V x 2
Screen Resolution
1920x1080
Hard Drives
256GB Vertex 4 SSD
2TB Seagate ST2000DM001
1TB Seagate ST1000DM003
PSU
Corsair HX 650
Case
HAF 932 advanced
Cooling
Corsair H100i liquid cooler
Keyboard
Logitech Wireless
Mouse
Logitech Wireless
Internet Speed
OptusNet NBN 100/40
Antivirus
Malwarebytes
Browser
Firefox 30
Other Info
Router: Sagemcom F@st 3846 Crippled by Optus.
Brilliant! thankyou so much :D
 

My Computer

Computer type
PC/Desktop
OS
windows 7 pro 64bit
CPU
Intel 3570k
Motherboard
asus maximus v gene
Memory
12GB
Graphics Card(s)
gtx 660
Hard Drives
2x 1TB WD
1x SSD
Antivirus
avast
Browser
icedragon
I have managed to get the command working when I ping an IP address however when I do nbtstat -a it just loops back to the start and I am unable to do the lookup, I have tried doing timeouts and goto command but it still doesn't seem to work! what am i doing wrong?:(
 

My Computer

Computer type
PC/Desktop
OS
windows 7 pro 64bit
CPU
Intel 3570k
Motherboard
asus maximus v gene
Memory
12GB
Graphics Card(s)
gtx 660
Hard Drives
2x 1TB WD
1x SSD
Antivirus
avast
Browser
icedragon
Can you post your batch file, please
 

My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Home Made
OS
Linux Mint 17 Cinnamon | Win 7 Ult x64
CPU
Intel I7-3770K @ 4.2ghz
Motherboard
ASRock Extreme 4
Memory
32GB G-Skill C10Q
Graphics Card(s)
EVGA GTX 670 2GB SC
Sound Card
Creative Fatality ExtremeGamer
Monitor(s) Displays
LG E2742V x 2
Screen Resolution
1920x1080
Hard Drives
256GB Vertex 4 SSD
2TB Seagate ST2000DM001
1TB Seagate ST1000DM003
PSU
Corsair HX 650
Case
HAF 932 advanced
Cooling
Corsair H100i liquid cooler
Keyboard
Logitech Wireless
Mouse
Logitech Wireless
Internet Speed
OptusNet NBN 100/40
Antivirus
Malwarebytes
Browser
Firefox 30
Other Info
Router: Sagemcom F@st 3846 Crippled by Optus.
this is what I have so far:

@ECHO OFF
set /p "id=Please enter an IP address: "
cls
Ping %ID%
nbtstat -a %id%

it successfully pings however it doesn't do the nbtstat look up it just jumps back "please enter an IP address"
 

My Computer

Computer type
PC/Desktop
OS
windows 7 pro 64bit
CPU
Intel 3570k
Motherboard
asus maximus v gene
Memory
12GB
Graphics Card(s)
gtx 660
Hard Drives
2x 1TB WD
1x SSD
Antivirus
avast
Browser
icedragon
Ok, that looks fine to me.
And indeed, it runs perfectly for me.
Here's the output.

Code:
Pinging 192.168.1.2 with 32 bytes of data:
Reply from 192.168.1.2: bytes=32 time=2ms TTL=128
Reply from 192.168.1.2: bytes=32 time=1ms TTL=128
Reply from 192.168.1.2: bytes=32 time=2ms TTL=128
Reply from 192.168.1.2: bytes=32 time=2ms TTL=128

Ping statistics for 192.168.1.2:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 1ms, Maximum = 2ms, Average = 1ms

Local Area Connection:
Node IpAddress: [192.168.1.2] Scope Id: []

           NetBIOS Remote Machine Name Table

       Name               Type         Status
    ---------------------------------------------
    WORKGROUP      <00>  GROUP       Registered
    TANYA-PC       <00>  UNIQUE      Registered
    TANYA-PC       <20>  UNIQUE      Registered
    WORKGROUP      <1E>  GROUP       Registered
    WORKGROUP      <1D>  UNIQUE      Registered
    ..__MSBROWSE__.<01>  GROUP       Registered

    MAC Address = BC-5F-F4-45-5C-B8
I ran it from my desktop, then from my C:\ drive, then as a scheduled task. It worked perfectly every time. I even ran it from within another cmd file, and then "called" it from within another cmd file. Works every time.

So, how are you running it?

Tanya
 

My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Home Made
OS
Linux Mint 17 Cinnamon | Win 7 Ult x64
CPU
Intel I7-3770K @ 4.2ghz
Motherboard
ASRock Extreme 4
Memory
32GB G-Skill C10Q
Graphics Card(s)
EVGA GTX 670 2GB SC
Sound Card
Creative Fatality ExtremeGamer
Monitor(s) Displays
LG E2742V x 2
Screen Resolution
1920x1080
Hard Drives
256GB Vertex 4 SSD
2TB Seagate ST2000DM001
1TB Seagate ST1000DM003
PSU
Corsair HX 650
Case
HAF 932 advanced
Cooling
Corsair H100i liquid cooler
Keyboard
Logitech Wireless
Mouse
Logitech Wireless
Internet Speed
OptusNet NBN 100/40
Antivirus
Malwarebytes
Browser
Firefox 30
Other Info
Router: Sagemcom F@st 3846 Crippled by Optus.
Ive tried it from desktop and c drive and it still loops
http://postimg.org/image/en98ot5jz/ thats whats happening :(
I have full admin permission so thats not the problem either
 

My Computer

Computer type
PC/Desktop
OS
windows 7 pro 64bit
CPU
Intel 3570k
Motherboard
asus maximus v gene
Memory
12GB
Graphics Card(s)
gtx 660
Hard Drives
2x 1TB WD
1x SSD
Antivirus
avast
Browser
icedragon
Hi,

Well, I've spent the last day trying to recreate your problem. Tried it on XP, Windows 7, Windows 8 and 8.1. I tried it on a standard user account, and an administrator account. No matter what I do I can't recreate the problem you're having. This is really bizarre :confused:

I'll keep digging and trying different things....

Meanwhile, if any other knowledgeable people are passing by hopefully they will chime in..

btw, should probably add "Set id=" (minus the quotes) as the last line just to clean up after. That will delete the environment variable.



Tanya
 

My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Home Made
OS
Linux Mint 17 Cinnamon | Win 7 Ult x64
CPU
Intel I7-3770K @ 4.2ghz
Motherboard
ASRock Extreme 4
Memory
32GB G-Skill C10Q
Graphics Card(s)
EVGA GTX 670 2GB SC
Sound Card
Creative Fatality ExtremeGamer
Monitor(s) Displays
LG E2742V x 2
Screen Resolution
1920x1080
Hard Drives
256GB Vertex 4 SSD
2TB Seagate ST2000DM001
1TB Seagate ST1000DM003
PSU
Corsair HX 650
Case
HAF 932 advanced
Cooling
Corsair H100i liquid cooler
Keyboard
Logitech Wireless
Mouse
Logitech Wireless
Internet Speed
OptusNet NBN 100/40
Antivirus
Malwarebytes
Browser
Firefox 30
Other Info
Router: Sagemcom F@st 3846 Crippled by Optus.
Hi Tanya, I really appreciate that you have been helping and tried so many ways to get around the issue!
ive had the thought, would the issue be occurring due to the fact that im on a domain?
will add that line now:)
Thanks again for all the help!
-Lewis
 

My Computer

Computer type
PC/Desktop
OS
windows 7 pro 64bit
CPU
Intel 3570k
Motherboard
asus maximus v gene
Memory
12GB
Graphics Card(s)
gtx 660
Hard Drives
2x 1TB WD
1x SSD
Antivirus
avast
Browser
icedragon
Hi Lewis,

Not sure about the domain side of things. It's been a decade since I worked with domains/active directory and a lot has changed over the years. With most of my machines now converted to Linux, I'm going to find it difficult to test a domain scenario.

However, based on past experience, I don't see why being a member of a domain would make a lot of difference. The machine could be locked down by policy, but (and I could be forgetting something here), I don't think there is anything there that would cause this type of behavior.

I got a couple of friends to test the script and it worked fine for them. I'll see if I can track down some old contacts that are on a domain and see it they can test it for me too.

Just out of curiosity, you haven't named the batch file ping.bat or nbtstat.bat have you (or ping.cmd/nbtstat.cmd).. That will cause a mess ;)
 

My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Home Made
OS
Linux Mint 17 Cinnamon | Win 7 Ult x64
CPU
Intel I7-3770K @ 4.2ghz
Motherboard
ASRock Extreme 4
Memory
32GB G-Skill C10Q
Graphics Card(s)
EVGA GTX 670 2GB SC
Sound Card
Creative Fatality ExtremeGamer
Monitor(s) Displays
LG E2742V x 2
Screen Resolution
1920x1080
Hard Drives
256GB Vertex 4 SSD
2TB Seagate ST2000DM001
1TB Seagate ST1000DM003
PSU
Corsair HX 650
Case
HAF 932 advanced
Cooling
Corsair H100i liquid cooler
Keyboard
Logitech Wireless
Mouse
Logitech Wireless
Internet Speed
OptusNet NBN 100/40
Antivirus
Malwarebytes
Browser
Firefox 30
Other Info
Router: Sagemcom F@st 3846 Crippled by Optus.
Hi Lewis,

Not sure about the domain side of things. It's been a decade since I worked with domains/active directory and a lot has changed over the years. With most of my machines now converted to Linux, I'm going to find it difficult to test a domain scenario.

However, based on past experience, I don't see why being a member of a domain would make a lot of difference. The machine could be locked down by policy, but (and I could be forgetting something here), I don't think there is anything there that would cause this type of behavior.

I got a couple of friends to test the script and it worked fine for them. I'll see if I can track down some old contacts that are on a domain and see it they can test it for me too.

Just out of curiosity, you haven't named the batch file ping.bat or nbtstat.bat have you (or ping.cmd/nbtstat.cmd).. That will cause a mess ;)

I cant believe it! I had it named nbtstat.bat all along and renaming it fixed it! Thankyou so much for your help!! I appreciate it a ton!
 

My Computer

Computer type
PC/Desktop
OS
windows 7 pro 64bit
CPU
Intel 3570k
Motherboard
asus maximus v gene
Memory
12GB
Graphics Card(s)
gtx 660
Hard Drives
2x 1TB WD
1x SSD
Antivirus
avast
Browser
icedragon
Just out of curiosity, you haven't named the batch file ping.bat or nbtstat.bat have you (or ping.cmd/nbtstat.cmd).. That will cause a mess ;)

I cant believe it! I had it named nbtstat.bat all along and renaming it fixed it! Thankyou so much for your help!! I appreciate it a ton!

:party:

calling a batch file by the same name it contains a command for would cause it to loop. So nbtstat.bat would simply keep calling nbtstat.bat from within the batch file.

Have fun.

Tanya
 

My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Home Made
OS
Linux Mint 17 Cinnamon | Win 7 Ult x64
CPU
Intel I7-3770K @ 4.2ghz
Motherboard
ASRock Extreme 4
Memory
32GB G-Skill C10Q
Graphics Card(s)
EVGA GTX 670 2GB SC
Sound Card
Creative Fatality ExtremeGamer
Monitor(s) Displays
LG E2742V x 2
Screen Resolution
1920x1080
Hard Drives
256GB Vertex 4 SSD
2TB Seagate ST2000DM001
1TB Seagate ST1000DM003
PSU
Corsair HX 650
Case
HAF 932 advanced
Cooling
Corsair H100i liquid cooler
Keyboard
Logitech Wireless
Mouse
Logitech Wireless
Internet Speed
OptusNet NBN 100/40
Antivirus
Malwarebytes
Browser
Firefox 30
Other Info
Router: Sagemcom F@st 3846 Crippled by Optus.
Back
Top