簡體   English   中英

如何使用nodejs獲取連接到另一個局域網的所有設備的ip和mac地址?

[英]How to fetch ip and mac addresses of all the devices connected to another LAN using nodejs?

如何使用 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 install sudo apt-get install arp-scan

只需更改命令sudo arp-scan -l

這將為您提供所有信息

您可以使用任何 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

   }

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM