I am updating out DHCP config and wrote this script to get the MAC address of a remote computer on the network. It works fine if I leave the errorlevel part out of it, but I want the errorlevel included so it ECHO's that the host was not found, if it wasn't found. I just can't seem to get it to work. Does ping.exe have errorlevels? Here's the script:
:start
cls
@echo off
title getMACecho Clearing ARP Cache . . .
netsh interface ip delete arpcacheecho Enter IP address of remote computer:
set /p ip=for %%i in (%ip%) do ping -n 1 %%i
cls
if %errorlevel% == 1 (
goto fail
) else (
arp -a | findstr "%%i"
):fail
echo Host not found, or not alive . . .pause
goto start
cls
No matter what, it always ECHO's Host not found, or not alive . . . and doesn't output anything else. The MAC and IP address should be displayed on stdout.In the script below it
:start
cls
@echo offtitle getMAC
echo Clearing ARP Cache . . .
netsh interface ip delete arpcacheecho Enter IP address of remote computer:
set /p ip=for %%i in (%ip%) do (ping -n 1 %%i
cls
arp -a | findstr "%%i"
)pause
goto start
clsThe above script works exactly as it is suppossed to.
What's wrong with my first script? Or does ping.exe not have errorlevels at all?
UNIX is an operating system, OS/2 is half an operating system, Windows is a shell, and DOS is a boot partition virus.

I've gotten it to work if the host is found (errorlevel 0), but not if the host isn't found (errorlevel 1). Here's the revised script:
:start
cls
@echo offtitle getMAC
echo Clearing ARP Cache . . .
netsh interface ip delete arpcacheecho Enter IP address of remote computer:
set /p ip=for %%i in (%ip%) do (ping -n 1 %%i
if %errorlevel% == 1 (
goto fail
) else (
cls
arp -a | findstr "%%i"
)
)pause
goto start
cls:fail
echo Host not found, or not alive . . .
goto start
When the errorlevel == 1, it doesn't ECHO Host not found, or not alive . . . It just goes to :start.Any suggestions?
Thanks,
Tony
login: yes
password: dont have onepassword is incorrect
login: yes
password: incorrect
Hi Tony, Try this:
[I dunno arp, but I think you'll get the idea.]
::== checkIP.bat
@echo off
:newIP
set /p ip= ip num ?
if %ip%'==0' goto :eof
ping -n 1 %ip% | find "Reply" > nul
if errorlevel 1 echo no reply && goto :newIP
goto :newIP
:: DONE
Enetring 0 gives you a way out.
=====================================
If at first you don't succeed, you're about average.M2
Alright, I'll give it a try and post back. Thanks alot,
Tony
login: yes
password: dont have onepassword is incorrect
login: yes
password: incorrect
