如何使用nodejs或任何powershell脚本获取连接到同一组织中不同LAN的所有设备的ip和mac地址?
在这里,您可以使用child_process
找到
像这样的东西。
const { exec } = require("child_process");
function os_func() {
this.execCommand = function(cmd, callback) {
exec(cmd, (error, stdout, stderr) => {
if (error) {
console.error(`exec error: ${error}`);
return;
}
callback(stdout);
});
}
}
var os = new os_func();
os.execCommand('arp -a', function (returnvalue) {
console.log(returnvalue)
});
或者您可以使用arp-scan
安装sudo apt-get install arp-scan
刚刚更改命令sudo arp-scan -l
这将为您提供所有信息
您可以在任何windows计算机上运行此PowerShell脚本。将您的主机名放入主机名文本中。只要您能够ping运行脚本的主机名。
$hostname = get-content -path "C:temphostname.txt"
Foreach ($computer in $hostname) {
$ping = Test-Connection -Name $computer -count 2 -Quiet
If ($ping -eq $true) {
$prop = Get-Ciminstance -ClassName Win32_NetorkAdapterConfiguration -ComputerName $computer | select IPAddress, MacAddress, PSComputerName
Write-Host $prop
}
}