Pinging & IP addresses plus findstr thrown in

August 30, 2010 at 02:49:57
Specs: Multiple OS, -
You can put an IP address in with "ping -a" (gives you IP computer name)
It does this:
Pinging "Computer" [*.*.*.*] with 32 bytes of data:
Reply from *.*.*.*: bytes=32 time<1ms TTL=128
Reply from *.*.*.*: bytes=32 time<1ms TTL=128
Reply from *.*.*.*: bytes=32 time<1ms TTL=128
Reply from *.*.*.*: bytes=32 time<1ms TTL=128

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

Can it be possible to get the just "computer" [*.*.*.*] from the first line and put it into ether a variable or a file?? using findstr...
I work at a school where i can ping the IP address to see if the computer is working BUT we dont find he computers by IP address... we use the computer name.
Any help will be great! Thanks


See More: Pinging & IP addresses plus findstr thrown in

Report •

#1
August 30, 2010 at 05:04:44
Try This:

@ECHO ON

FOR /f "tokens=2* delims= " %%a IN ('PING /a IPADDRESS') DO (
	SET Variable=%%a
	GOTO Done
)

:Done

ECHO %Variable%
PAUSE

Good Luck

Can I put a question here?


Report •

#2
August 31, 2010 at 23:52:31
Works great!

THANKS!


Report •

#3
September 3, 2010 at 11:39:38
Sounds like you might benefit from something I wrote a while back for work. Basically this used dsquery (assuming you're in an AD environment) to query a portion of the computer name, pings those computers that are returned by the dsquery search, and shows whether each is online or not.

This allows me to not only find a computer with only a portion of the name but also see whether it's up or not (in a list format) and go from there. I added it to my system path as pingf.bat and simply call it by typing "pingf comp" where comp is a partial computer name. I've ended up using it on a daily basis:

@echo off
setlocal ENABLEDELAYEDEXPANSION
cls
Ping -w 150 %1
IF %errorlevel% NEQ 0 GOTO LOCATE
GOTO END

:LOCATE
CLS

Del /f /q status.txt
Del /f /q comps.txt
CLS
Echo Computer names similar to your entry:
Echo.
Echo.
DSQUERY computer -limit 250 -name *%1* -o rdn >>comps.txt


for /f %%a in (comps.txt) do (
ping %%a -n 1 -w 100 >nul
if !errorlevel! equ 0 (Echo %%a - Online >>status.txt.) else Echo %%a - Offline >>status.txt.
)

Echo.
CLS
type status.txt
Echo.
Echo For more results - please try again with a more broad computer name.
Echo.
Echo.
:END


Report •
Related Solutions


Ask Question