Problem mit Übergabeparameter in FOR-Schleife
Hallo,
ich bräuchte nochmal Hilfe von den Batch Gurus..
Ich möchte die Ausgabe eines CMD-Befehls nach einer IP durchsuchen (find) und das Ergebnis in eine Variable schreiben, scheitere aber an dem Übergabeparameter.
Also.. %1 ist xxx.xxx.xxx.204
for /f "tokens=2" %%a in ('arp -a ^| find "%1"') do set macstring=%%a funktioniert nicht
arp -a | find "%1" funktioniert wiederum
for /f "tokens=2" %%a in ('arp -a ^| find "204"') do set macstring=%%a funktioniert auch
Das Problem kann ja jetzt nur sein, dass ich das %1 für das find irgendwie escapen muss, scheitere aber kläglich. Kann jemand helfen? Vielen Dank im voraus!
Gruß vbanfaenger
ich bräuchte nochmal Hilfe von den Batch Gurus..
Ich möchte die Ausgabe eines CMD-Befehls nach einer IP durchsuchen (find) und das Ergebnis in eine Variable schreiben, scheitere aber an dem Übergabeparameter.
Also.. %1 ist xxx.xxx.xxx.204
for /f "tokens=2" %%a in ('arp -a ^| find "%1"') do set macstring=%%a funktioniert nicht
arp -a | find "%1" funktioniert wiederum
for /f "tokens=2" %%a in ('arp -a ^| find "204"') do set macstring=%%a funktioniert auch
Das Problem kann ja jetzt nur sein, dass ich das %1 für das find irgendwie escapen muss, scheitere aber kläglich. Kann jemand helfen? Vielen Dank im voraus!
Gruß vbanfaenger
Please also mark the comments that contributed to the solution of the article
Content-Key: 506321
Url: https://administrator.de/contentid/506321
Printed on: April 19, 2024 at 22:04 o'clock
1 Comment
Das Problem kann ja jetzt nur sein, dass ich das %1 für das find irgendwie escapen muss
Nö.Geht doch ...
@echo off & setlocal
set "macstring="
for /f "tokens=2" %%a in ('arp -a "%~1" ^|find " %~1 "') do set "macstring=%%a"
if defined macstring (
echo %macstring%
) else (
echo MAC fuer IP nicht gefunden.
)