Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do you capture the IP address when you ping the server

Status
Not open for further replies.

tbscmgi

MIS
Sep 17, 2003
66
US
To All-
How can I capture the IP address when I ping the server by it name?
Thanks
 
Try this:

C:\>ping servername >C:\ip.txt

It will create a txt file with the ping outcome...

Brandon
 
Yay! Batch! Let me play!

Assuming you have the target host name in a variable called 'host' then...

From the command line:
Code:
for /f "delims=[] tokens=2" %a in ('ping -n 1 %host% ^| findstr /i /c:"Pinging"') do @echo %host% %a>>IPs.txt

Or from a batch file:
Code:
for /f "delims=[] tokens=2" %%a in ('ping -n 1 %host% ^| findstr /i /c:"Pinging"') do @echo %host% %%a>>IPs.txt

Target hit?

JJ
[small][purple]Variables won't. Constants aren't[/purple]
There is no apostrophe in the plural of PC (or PST, or CPU, or HDD, or FDD, and so on)[/small]
 
Why not simply use nslookup ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top