Anyone REALLY Good in Batch?

hevnsnt

Lifer
Mar 18, 2000
10,868
1
0
I am trying to do a simple line that will resolve an hostname into an IP.. Here is where I am at.


FOR /F "tokens=3 delims= " %%A IN ('PING -a %1 -n 1 ^| FIND "Reply"') DO ECHO.%%A

Now, this will return the IP as such 1.2.3.4: I need to be able to remove the ":" from the variable.. Anyone know how to do this?

 

Jzero

Lifer
Oct 10, 1999
18,834
1
0
Originally posted by: hevnsnt
I figured it out using nslookup instead of ping.. thanks :)

Nslookup is the way to do it.

Ping is a PITA for this b/c it gives you too much extra info to strip out. About the easiest way to do it would be to take your result IP address and run it through a FOR /F using . as the delim, which effectively strips it out.

Edit: Misread.
If you had added : as a delim, you would strip it out. Thought you wanted to get the dots out.

FOR /F "tokens=3 delims=: " %%A IN ('PING -a %1 -n 1 ^| FIND "Reply"') DO ECHO.%%A