Objective:
The goal of this script is to determine whether a machine is physical or virtual across multiple operating systems (Windows, Linux, and macOS). This capability is valuable for system administrators, security professionals, and developers to understand their environment for operational or security assessments.
1. Script Overview:
Functionality:
The script checks the system’s hardware and software characteristics to identify virtualization indicators. It retrieves system information using OS-specific commands and compares the output against known patterns that signify a virtual environment.
Target Operating Systems:
•Windows
•Linux
•macOS
2. How the Script Works:
Step-by-Step Process:
1.OS Detection:
The script uses Python's platform.system() to identify the operating system:
os_type = platform.system()
2.Windows Detection:
oUses the wmic command to retrieve system model information.
oSearches for keywords like "Virtual", "VMware", "VirtualBox", or "Hyper-V" in the output.
oPrints the model information for debugging.
result = subprocess.check_output("wmic computersystem get model", shell=True, text=True)
3.Linux Detection:
oRetrieves product and vendor names from system files (/sys/class/dmi/id/product_name and /sys/class/dmi/id/sys_vendor).
oChecks for a hypervisor using the lscpu command.
oPrints key outputs to help diagnose false positives.
product_name = subprocess.check_output("cat /sys/class/dmi/id/product_name", shell=True, text=True).strip()
4.macOS Detection:
oRuns the sysctl command to inspect CPU features.
oChecks for virtualization-related flags, particularly the "VMM" feature.
sysctl_output = subprocess.check_output("sysctl -a | grep machdep.cpu.features", shell=True, text=True).strip()
5.Unsupported Systems:
If the operating system is not recognized, it displays a message indicating the system is unsupported.
3. Usage Instructions:
1.Prerequisites:
Ensure Python is installed on the target machine.
2.Execution:
oSave the script to a .py file (e.g., check_vm.py).
oOpen a terminal (Linux/macOS) or Command Prompt (Windows).
oNavigate to the script’s directory and run:
python check_vm.py
3.Expected Output:
The script will print:
oDetected operating system.
oRelevant system information (e.g., model or vendor name).
oFinal determination: "This is a Virtual Machine" or "This is a Physical Machine."
اسم المستقل | Mohammed A. |
عدد الإعجابات | 0 |
عدد المشاهدات | 11 |
تاريخ الإضافة |