Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for restart_ethernet.bat

(view source code of restart_ethernet.bat as plain text)

  1. @ECHO OFF
  2. :: Check command line
  3. IF NOT "%~2"=="" GOTO Syntax
  4. SET Delay=5
  5. IF NOT "%~1"=="" SET /A Delay=%1
  6. IF %Delay% LSS 5 (ECHO. & ECHO ERROR: Delay must be in 5..120 seconds range & GOTO Syntax)
  7. IF %Delay% GTR 120 (ECHO. & ECHO ERROR: Delay must be in 5..120 seconds range & GOTO Syntax)
  8. :: Check for elevated privileges
  9. OPENFILES.EXE >NUL 2>&1 || (ECHO. & ECHO ERROR: This batch file requires elevated privileges & GOTO Syntax)
  10.  
  11. :: Show current IP address
  12. IPCONFIG.EXE
  13. :: Disable Ethernet network adapter
  14. NETSH.EXE Interface Set Interface name=Ethernet admin=DISABLED
  15. :: Wait
  16. TIMEOUT.EXE %Delay% /NoBreak
  17. :: Enable Ethernet network adapter
  18. NETSH.EXE Interface Set Interface name=Ethernet admin=ENABLED
  19. :: Wait
  20. TIMEOUT.EXE %Delay% /NoBreak
  21. :: Renew and show new IP address
  22. IPCONFIG.EXE /Renew
  23. SET Delay=
  24. GOTO:EOF
  25.  
  26.  
  27. :Syntax
  28. SET Delay=
  29. ECHO.
  30. ECHO Restart_Ethernet.cmd, Version 1.01
  31. ECHO Restart Ethernet network adapter
  32. ECHO.
  33. ECHO Usage:  Restart_Ethernet.cmd  [ delay ]
  34. ECHO.
  35. ECHO Where:  delay   is the time in seconds to wait between disabling/enabling
  36. ECHO                 the network adapter and checking its new status
  37. ECHO                 ^(range: 5..120 seconds; default: 5 seconds^)
  38. ECHO.
  39. ECHO The batch file will disable the local Ethernet network adapter, wait for a
  40. ECHO number of seconds seconds, and then reenable the Ethernet network adapter.
  41. ECHO Elevated privileges are required.
  42. ECHO.
  43. ECHO Written by Rob van der Woude
  44. ECHO https://www.robvanderwoude.com/
  45. EXIT /B 1
  46.  

page last modified: 2024-04-16; loaded in 0.0049 seconds