:getHostName ip ret -- resolves IP address to computer name :: -- ip [in,opt] - ip, default is THIS computer's IP :: -- ret [out,opt] - computer name SETLOCAL set ip=%~1 if "%ip%"=="" call:getIP "" ip set name= for /f "tokens=2" %%a in ('"ping /a /n 1 %ip%|find "Pinging" 2>NUL"') do set name=%%a ENDLOCAL & IF "%~2" NEQ "" (SET %~2=%name%) ELSE (echo.%name%) EXIT /b