Page 1 of 1

set var from arp output.....i'm not sure how

Posted: 26 Mar 2010 12:40
by raylward102
Ive been working on this batch file that searches a mac address and informs of the ip address belonging to the mac. I can use:
arp -a | find "00-1C-C0-4A-ED-AD"

from the command prompt to get an output of:
192.168.0.223 00-1c-c0-4a-ed-ad dynamic

I want my batch file to set the ip address to a variable (%IP%) to be used in the later part of the batch file. At the moment; I was trying this:
@ECHO OFF
FOR /F "tokens=2,3 delims= " %%A IN ('arp -a | find "00-1C-C0-4A-ED-AD"') DO IF "%%B"=="[%1]" SET PC=%%A
echo %%A

Doesn't work at all though. Am I going in the wrong direction completely here? Any Idea's?

Re: set var from arp output.....i'm not sure how

Posted: 26 Mar 2010 13:03
by sxekjb
you can put the output of arp to a file and use it as a variable there using

Code: Select all

@echo off
set arp=arp -a
%arp% | find /i "00-1C-C0-4A-ED-AD" >>output.log
for /f "tokens=1,2,3 delims= " %%G IN (output.log) DO set IP=%%G
echo %IP%
pause
del output.log