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?
Displaying computer name
Moderator: DosItHelp
-
- Posts: 4
- Joined: 22 Dec 2010 10:33
Re: Displaying computer name
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
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
-
- Posts: 79
- Joined: 13 Dec 2010 10:32
Re: Displaying computer name
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