Advertisement
npocmaka

isLocalhost.bat

Jan 21st, 2013
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @echo off
  2. rem -- check if a given host is lcalhost
  3. rem -- by Vasil "npocmaka" Arnaudov
  4. setlocal
  5. set /A errorlevel=0
  6. if "%1" EQU "" (
  7.     echo %~n0 hostname
  8.     echo set errorlevel to 1 if the host is localhost and 2 if host is not found
  9. )
  10.  
  11. if "%1" EQU "/?" (
  12.     echo %~n0 hostname
  13.     echo set errorlevel to 1 if the host is localhost and 2 if host is not found
  14. )
  15.  
  16. set ping_result=
  17. for /f %%P in ('call ping -n 1 %1  ^| find "could not find host"') do (
  18.  set ping_result=%%P
  19. ) > nul
  20.  
  21. if "%ping_result%" NEQ "" (
  22.     echo host not found
  23.     endlocal & exit /b 2
  24.     goto :eof
  25. )
  26.  
  27. setlocal ENABLEDELAYEDEXPANSION
  28. for /f "tokens=1,2,* delims= " %%W in ('wmic  /node:%1 /user:? /password:? process get 2^>^&1 ^| findstr "Description" ') do (
  29.      
  30.     rem the commented echo produces a strange result
  31.     rem  echo --%%Y--
  32.     call set resp=%%Y
  33.    
  34.     if [!resp!] EQU [User credentials cannot be used for local connections]  (
  35.         endlocal
  36.         endlocal & exit /b 1
  37.     )
  38. )
  39. endlocal
  40. endlocal
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement