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

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
raylward102
Posts: 9
Joined: 26 Mar 2010 12:30

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

#1 Post by raylward102 » 26 Mar 2010 12:40

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?

sxekjb
Posts: 16
Joined: 07 Nov 2009 19:13

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

#2 Post by sxekjb » 26 Mar 2010 13:03

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

Post Reply