开发者

Determine whether MAC address is physical or virtual on Linux

I have tried using several commands as well as couple of examples using C/C++ but am still not able to find a flawless method that can differentiate between physical or virtual ethernet adapters. Physical means, on that available on your board or installed externally and virtual means created by virtualization apps such as VirtualBox/VMWare/Virtual 开发者_运维百科PC or VPN etc.

Any pointers?


There is no flawless method. A virtual adapter can have any MAC address, including one that might have been assigned by a constructor to a physical device. And the other way around, given that one can change the MAC address of a physical adapter. You can only make an educated guess.


You might find it easier to detect if you are running virtualized at all, rather than look for specific information about the NICs. The virt-what(1) tool looks through aspects of the running system to guess if the system is virtualized or not. (The script isn't as smart as you think, but it does have a lot of small information gathering tools in one place.)

Someone intentionally trying to bypass a license check would probably not find it difficult to defeat this mechanism.


Maybe one can use mii-tool and check if it fails, which it does for virtual:

mii-tool vmbr2
SIOCGMIIPHY on 'vmbr2' failed: Operation not supported
mii-tool eno1
eno1: negotiated 1000baseT-FD flow-control, link ok

EDIT:

What is mii-tool: view, manipulate media-independent interface status

   This utility checks or sets the status of a network interface's
   Media Independent Interface (MII) unit.  Most fast ethernet
   adapters use an MII to autonegotiate link speed and duplex
   setting.

https://www.man7.org/linux/man-pages/man8/mii-tool.8.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜