Displaying computer name

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

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

Displaying computer name

#1 Post by tbharber » 29 Oct 2010 13:11

I am trying to write a script to display a computers name if the IP Address is entered. I cant get the code to display it correctly. Currently this is what I have....

for /f "tokens=2 delims=g[" %%a in ('ping -a %ipaddress% ^|find "Pinging"') do echo Current Computer Name / IP: %ipaddress% / %%a

When run it should display it as:
"ipaddress / computername"

What I want is for it to display what is between the word Pinging and the [ symbol. the problem is there is more than one g in the line so the code does not work correctly.

Any thoughts?

ScriptKing
Posts: 4
Joined: 22 Dec 2010 10:33

Re: Displaying computer name

#2 Post by ScriptKing » 28 Dec 2010 06:02

Hi,

I think this will work for you:


for /f "tokens=2 delims=[] " %%a in ('"ping -a %ipaddress% |find "Pinging""') do echo Current Computer Name / IP: %ipaddress% / %%a

ChickenSoup
Posts: 79
Joined: 13 Dec 2010 10:32

Re: Displaying computer name

#3 Post by ChickenSoup » 28 Dec 2010 07:49

Actually the only delimiter you need is a space. like so:

Code: Select all

for /f "tokens=2 delims= " %%a in ('ping -a %ipaddress% ^|find "Pinging"') do echo Current Computer Name / IP: %ipaddress% / %%a

Post Reply