Page 1 of 1

Displaying computer name

Posted: 29 Oct 2010 13:11
by tbharber
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?

Re: Displaying computer name

Posted: 28 Dec 2010 06:02
by ScriptKing
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

Re: Displaying computer name

Posted: 28 Dec 2010 07:49
by ChickenSoup
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