Skip to content

Instantly share code, notes, and snippets.

@filimonov
Last active August 9, 2020 18:08
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save filimonov/58779d1495e81568fb36a52463d2bdb1 to your computer and use it in GitHub Desktop.
Save filimonov/58779d1495e81568fb36a52463d2bdb1 to your computer and use it in GitHub Desktop.
"Replug" the cable of running VirtualBox VM (network freeze in guest VM after host windows hybernate - awake)
@echo off
set VboxManageEXE="%VBOX_MSI_INSTALL_PATH%\VBoxManage.exe"
set ListRunningVMS=%VboxManageEXE% list runningvms
for /f tokens^=2^,4^ delims^=^" %%p in ('%ListRunningVMS%') do (
echo "%%p"
%VBoxManageEXE% controlvm %%p setlinkstate1 off
%VBoxManageEXE% controlvm %%p setlinkstate1 on
)
@filimonov
Copy link
Author

filimonov commented Nov 25, 2018

Related to

Generally it gets the list of running machines, and after that for each VM calls:

VBoxManage controlvm "machine_name" setlinkstate1 off   # unplug the cable from network card #1 
VBoxManage controlvm "machine_name" setlinkstate1 on    # plug the cable back 

Adjust the script if you use multiple network cards (setlinkstate - where N is the number of network card).

Iteration on active vms is based on https://superuser.com/a/1184354

@jportoles
Copy link

jportoles commented Apr 7, 2019

If the method above doesn't work, replace:

%VBoxManageEXE% controlvm %%p setlinkstate1 off
%VBoxManageEXE% controlvm %%p setlinkstate1 on

With:

%VBoxManageEXE% controlvm %%p nicpromisc1 deny
%VBoxManageEXE% controlvm %%p nicpromisc1 allow-all

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment