【发布时间】:2020-10-28 16:54:12
【问题描述】:
如何使用 nodejs 或任何 powershell 脚本获取连接到同一组织中不同 LAN 的所有设备的 ip 和 mac 地址?
【问题讨论】:
标签: node.js windows powershell ip mac-address
如何使用 nodejs 或任何 powershell 脚本获取连接到同一组织中不同 LAN 的所有设备的 ip 和 mac 地址?
【问题讨论】:
标签: node.js windows powershell ip mac-address
在这里你可以使用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
这将为您提供所有信息
【讨论】:
arp-scan 将有其他选择,您只需更改 cmd。代码将返回一切。
您可以在任何 Windows 机器上运行此 PowerShell 脚本。将您的主机名放入主机名文本中。只要您能 ping 通您正在运行脚本的主机名。
$hostname = get-content -path "C:\temp\hostname.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
}
}
【讨论】: