Mark is a graph advocate and field engineer for Neo Technology, the company behind the Neo4j graph database. As a field engineer, Mark helps customers embrace graph data and Neo4j building sophisticated solutions to challenging data problems. When he's not with customers Mark is a developer on Neo4j and writes his experiences of being a graphista on a popular blog at http://markhneedham.com/blog. He tweets at @markhneedham. Mark is a DZone MVB and is not an employee of DZone and has posted 534 posts at DZone. You can read more from them at their website. View Full User Profile

A crude way of telling if a remote machine is a VM

07.28.2011
| 4272 views |
  • submit to reddit

We were doing a bit of profiling of a data importing process we’ve been running across various environments and wanted to check whether or not one of the environments was a physical machine or a VM.

A bit of googling first led me to the following site where you can fill a MAC address and it will tell you which vendor it belongs to.

macvendorlookup.com is even better though because it’s more easily scriptable!

If I wanted to find the vendor of my MAC address on the ethernet port I could try the following:

ifconfig | grep -A1 en1 | grep ether | cut -d" " -f2 | xargs -I {} 
curl -s http://www.macvendorlookup.com/getoui.php?mac={} -o - | sed -e :a -e 's/<[^>]*>//g;/</N;//ba'

Which gives:

Vendor: Apple Inc

Sed magic was shamelessly stolen from sed one liners.

As it turns out the machine we wanted to learn about was a VM hosted on VMWare!

From http://www.markhneedham.com/blog/2011/07/27/a-crude-way-of-telling-if-a-remote-machine-is-a-vm/

0
Your rating: None
Published at DZone with permission of Mark Needham, author and DZone MVB.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Tags:

Comments

Mauro Bertapelle replied on Thu, 2011/07/28 - 7:45am

your script works only on macosx systems, as ifconfig output is completely different on other *nix

Anyway,  this is a more compact version (but still only usable on macs):

set `ifconfig |grep -A1 en1|grep ether`; curl -s http://www.macvendorlookup.com/getoui.php?mac=$2| grep -o 'Vendor:[^<]*'

 

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.