Advertisement
hidde663

getconnections.bat

Sep 25th, 2018
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. ::" "
  2. ::displays the active "ESTABLISHED" connections on screen, details include: "from" adress, "to" adress, application PID and imagename,meaning application name
  3. @echo off&setlocal enabledelayedexpansion
  4. for /f "tokens=1 delims=:" %%a in (%~nx0) do set "tab=%%~a"&goto escapeloop
  5. :escapeloop
  6. if "%1"=="/?" call :help
  7. if "%1"=="??" call :help
  8. if "%1"=="-h" call :help
  9. if "%1"=="help" call :help
  10. if "%1"=="-resolve" (set switch=fo) else set switch=o
  11. for /f "skip=4 tokens=2,3,5" %%a in ('netstat -%switch%') do (
  12. set "tab1=!tab!"
  13. set "tab2=!tab!"
  14. set "tab3=!tab!"
  15. call :strlen ans %%a
  16. if "!ans!" LSS "16" (set "tab1=!tab!!tab!")
  17. call :strlen ans %%b
  18. if "!ans!" LSS "40" set "tab2=!tab!!tab!"
  19. if "!ans!" LSS "32" (set "tab2=!tab!!tab!!tab!")
  20. if "!ans!" LSS "24" (set "tab2=!tab!!tab!!tab!!tab!")
  21. if "!ans!" LSS "16" (set "tab2=!tab!!tab!!tab!!tab!!tab!")
  22. call :strlen ans %%c
  23. if "!ans!" LSS "3" (set "tab3=!tab!!tab!")
  24. set/p "=%%a!tab1!-->!tab!%%b!tab2!-->!tab!PID: %%c!tab3!--> "<nul
  25. for /f "tokens=1,2" %%1 in ('tasklist') do if "%%2"=="%%c" set/p "=%%1"<nul
  26. if "%%c"=="0" set/p "=System Idle Process"<nul
  27. echo.
  28. )
  29. exit/b
  30. :help
  31. echo.
  32. echo switches /? -h /? ?? and help will all display this message
  33. echo.
  34. echo switch -resolve does:
  35. echo.
  36. echo Displays Fully Qualified Domain Names (FQDN) for foreign
  37. echo addresses.
  38. exit/b
  39. :strlen
  40. set l=0
  41. set "s=%~2#"
  42. for %%P in (512 256 128 64 32 16 8 4 2 1) do (
  43. if not "!s:~%%P,1!"=="" (
  44. set/a "l+=%%P"
  45. set "s=!s:~%%P!"
  46. )
  47. )
  48. set "%~1=%l%"
  49. exit /b
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement