
June 9th, 2009, 02:00 PM
|
|
n00b DevH'er
|
|
Join Date: Jun 2009
Posts: 1
Time spent in forums: 31 m 56 sec
Reputation Power: 0
|
|
|
Using GREP with batch file? (prettying up a program)
Hey there everybody. I'm a beginner in batch, and I felt like trying an IP finding program. Really basic stuff, I know, but I'm still learning. I just installed GREP to use with my program, to basically clean up the look.
Code:
@echo off
TITLE IP Address Finder
echo Welcome to Reece's IP address finder!
echo.
echo.
ping -n 2 127.0.0.1>nul
echo How to use:
echo.
echo 1. Enter the desired URL.
echo 2. Press "Enter".
echo 3. You should see the message "Pinging (URL)".
echo 4. Look inside the brackets after the URL for the IP address of the website.
echo.
echo.
ping -n 2 127.0.0.1>nul
set/p "url=>"
ping -n 2 >nul
ping %url%
echo.
echo.
echo.
echo Press any key to exit.
pause>nul
I want to ping the site to find the IP address, and then use GREP to display what is inside the brackets to clean it up. Now, I currently have no idea how to do this... Could anybody help me out?
EDIT:
I figured it out. For those of you looking to do something similar, I'll go ahead and post the code below. =) (yes, I did use GREP)
Code:
@echo off
TITLE IP Address Finder
echo Welcome to Reece's IP address finder!
echo.
echo.
ping -n 2 127.0.0.1>nul
echo How to use:
echo.
echo 1. Enter the desired URL.
echo 2. Press "Enter".
echo.
echo.
set/p "url=> "
echo.
echo.
ping %url% | grep -o -m 1 \[.*\]
echo.
echo.
echo Press any key to exit.
pause>nul
The
Code:
| grep -o -m 1 \[.*\]
was all I was missing. It cleaned it up very nicely. Feel free to use this code if you need it.
Last edited by Reece : June 9th, 2009 at 03:59 PM.
Reason: Figured it out
|