Page 1 of 1
Get IP from MAC adress?!
Posted: 24 Apr 2020 02:26
by tvogel
Hi, I´d like to get the IP of a given MAC adresss to ping a specific computer and check if it´s is online.
Yes, I just know the computers MAC adress - not it´s IP because it´s dynamic!
I startet with something like that and it works fine:
FOR /F %%i IN ('arp -a ^| find "12-34-56-78-90-ff"') DO set ip=%%i
But the problem is that I´d like to keep the MAC adress variable in the code (it´s given from outside to my skript).
So I tried something like that:
set mac=%1
FOR /F %%i IN ('arp -a ^| find "%mac%"') DO set ip=%%i
But the content of %mac% seams not to be processed and so the function will just return echo is off?!
Anybody out there who has a solution - even something totaly different which keeps track of my need of getting the IP of a given MAC adress???
ThanX a lot in advance - Thilo *;o(
Re: Get IP from MAC adress?!
Posted: 24 Apr 2020 15:17
by aGerman
What do you get if you invoke an
in your code?
Steffen
Re: Get IP from MAC adress?!
Posted: 25 Apr 2020 13:48
by Eureka!
This is what I use to connect an off-line NAS to a non-reserved DHCP address.
The intersting part for your case is the following line:
Code: Select all
for /f "usebackq" %%x in (`arp -a ^| findstr /i "%MAC%"`) do set IP=%%x
.. but in case you want to use it for something similar as I did (waking up NAS, getting IP-address and mapping a network share), I posted the entire script (without the personal details).
Note: there is a echo <bell character> after the net use M: \\... line; I don't know if it survived the forum editor.
If not: enter ALT-0-0-7 after the echo statement.
Code: Select all
@echo off
rem echo on
setlocal
::_______________________________________________________
::
:: SETTINGS
::_______________________________________________________
::
set MAC=00-11-22-33-44-55
set MAXTRIES=50
set INTERVAL=5
set USER=xxxx
set WW=xxxx
set PROGRAM=C:\Tools\wakemeonlan-x64\WakeMeOnLan.exe
::_______________________________________________________
::
:: INIT
::_______________________________________________________
::
set IP=
:: Disconnect old
net use M: /d 2>nul
::_______________________________________________________
::
:: ACTION
::_______________________________________________________
::
:: Wake up NAS
echo Waking up NAS
:: Wait for NAS to be alive
For /L %%x in (1,1,%MAXTRIES%) DO call :Loop %%x
:: NAS running; IP known. Connect ...
echo %TIME% - NAS running; IP known. Connect ...
echo.
:: NAS is running. Wait 5 seconds for shares to become available.
timeout 5
net use M: \\%IP%\Media %WW% /user:%IP%\%USER%
echo
echo NAS is on %IP%
goto :EOF
::===================================
:LOOP
::===================================
IF defined IP goto :EOF
echo %TIME% - attempt %1
"%PROGRAM%" /wakeup %MAC%
start /w "" "%PROGRAM%" /scan
for /f "usebackq" %%x in (`arp -a ^| findstr /i "%MAC%"`) do set IP=%%x
timeout %INTERVAL% > nul
goto :EOF
Re: Get IP from MAC adress?!
Posted: 27 Apr 2020 10:57
by tvogel
TahnX a lot. Where could i get the file you use? -> "C:\Tools\wakemeonlan-x64\WakeMeOnLan.exe"
Re: Get IP from MAC adress?!
Posted: 27 Apr 2020 11:06
by tvogel
aGerman wrote: ↑24 Apr 2020 15:17
What do you get if you invoke an
in your code?
Steffen
hi Steffen.
if i insert your code i´ll get the right output. %1 is echoing out the right ip.
but how to get this value in my variable %ip%?
thankX
Re: Get IP from MAC adress?!
Posted: 27 Apr 2020 11:15
by tvogel
aGerman wrote: ↑24 Apr 2020 15:17
What do you get if you invoke an
in your code?
Steffen
sorry i was not right!
i will get back the mac adress - not the ip. so i´ve got still the same problem ...
Re: Get IP from MAC adress?!
Posted: 29 Apr 2020 18:48
by Eureka!
tvogel wrote: ↑27 Apr 2020 10:57
TahnX a lot. Where could i get the file you use? -> "C:\Tools\wakemeonlan-x64\WakeMeOnLan.exe"
nirsoft.net (first hit when you google "wakemeonlan.exe")
BTW: You didn't try my solution?