Last active
February 11, 2019 21:50
-
-
Save mike-seger/5b3ec364de0f5b481e00055e46dae0ee to your computer and use it in GitHub Desktop.
List IP addresses of running VirtualBox VMs using nmap (works on OSX and Linux)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
networks=$(ifconfig|tr A-Z a-z|grep b[a-z]*st|sed -e "s/.*b[a-z]*st[: ]*//;s/ .*//;s#\$#/24#"|grep [0-9]/24) | |
netinfo=$(sudo nmap --min-rate 10000 --max-retries 0 --max-rtt-timeout 250ms -T 5 -n -sn $networks|\ | |
sed -e 's/Nmap scan report for /\$/'|tr '\n' '|'|tr '\$' '\n'|grep MAC|sed -e "s/|.*MAC [A-z]*: */|/;s/ [(].*//") | |
vboxmanage list runningvms|sed -e 's/[^"]{.*//'|tr -d '"'|grep '[A-z]'|while read name ; do | |
macs=$(vboxmanage showvminfo "$name" | grep NIC.*MAC: | awk '{print $4}' | \ | |
sed 's/.\{2\}/&:/g' | sed 's/.\{2\}$//'|tr '\n' '|') | |
printf '%s\n%s\n' "$name" "$netinfo" | egrep -i "($macs$name)" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment