Wie kann ich alle IPs im verbundenen Netzwerk über Terminal i auflisten?

Wie kann ich mithilfe der Ubuntu 10.10-Befehlszeile alle mit meinem Heimnetzwerk verbundenen IPs auflisten?

Im Idealfall muss es sich um einen CLI-Befehl handeln, da ich ihn von C++aus ausführen werde.

Author: Robert Houghton, 2011-03-24

9 answers

Check out the arp-scan - - Befehl - Sie werden wahrscheinlich haben, um es zu installieren zB:

sudo apt-get install arp-scan

Http://manpages.ubuntu.com/manpages/hardy/man1/arp-scan.1.html

Und um weitere Einzelheiten zu nennen:

sudo arp-scan --interface=eth0 --localnet

Wobei eth0 Ihr Gerät ist. Sie können Ihr Gerät finden mit:

ifconfig
 261
Author: Linker3000,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2013-03-25 07:05:39

Nmap Verwenden. beispiel: nmap -sn 10.10.10.0/24 Der ARP-Cache teilt Ihnen nur diejenigen mit, mit denen Sie kürzlich versucht haben, Kontakt aufzunehmen.

 126
Author: Keith,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2013-01-22 02:13:00

In Windows wäre dies arp -a ein Äquivalent dazu in Linux wäre arp -e.

Von der Seite man für arp:

arp with no mode specifier will print the current content of the table.
-e : Use default Linux style output format (with fixed columns).
 21
Author: David,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2020-12-28 16:34:53

Wenn Ihr Netzwerk 192.168.0.0/24 ist, erstellen Sie eine ausführbare Datei mit dem folgenden Code; Ändern Sie das 192.168.0 in Ihr tatsächliches Netzwerk.

#!/bin/bash
for ip in 192.168.0.{1..254}; do
  ping -c 1 -W 1 $ip | grep "64 bytes" &
done
 20
Author: Anders Larsson,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2016-04-09 23:15:39

Versuchen Sie zu installieren nmap (sudo apt-get install nmap) und geben Sie nmap 192.168.1.0/24 ein, indem Sie 192.168.1 durch die ersten drei Teile Ihrer IP-Adresse ersetzen (finden Sie es mit ip addr heraus).

Sie können auch eine etwas weniger genaue (meiner Erfahrung nach) Karte eines Netzwerks erhalten, indem Sie ping 192.168.1.255 ausführen (erneut 192.168.1 ersetzen), was sollte Geben Sie ein ping an jeden Computer im Netzwerk aus, funktioniert aber meiner Erfahrung nach nicht immer korrekt.

 14
Author: vktec,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2016-04-09 22:58:37

Für eine kompaktere Liste der angeschlossenen Geräte:

nmap -sL 192.168.0.* | grep \(1

Erklärung.

nmap -sL 192.168.0.* listet alle IPs im Subnetz auf und markiert diejenigen, die Namen haben:

Nmap scan report for 192.168.0.0
Nmap scan report for Dlink-Router.Dlink (192.168.0.1)
Nmap scan report for 192.168.0.2
...
Nmap scan report for android-473e80f183648322.Dlink (192.168.0.53)
...
Nmap scan report for 192.168.0.255

Da alle interessanten Datensätze mit Klammern ( und Ziffern 1 beginnen, filtern wir dies mit | grep \(1 (Backslash wird benötigt, um Klammern zu entkommen)

Quirk
Beachten Sie, dass, wenn zwei Geräte den gleichen Namen haben, nmap zeigt nur die eine, das war verbunden Router letzte

 3
Author: Alexander Malakhov,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2016-10-22 09:09:47

Kam auf einem Nexus mit tmux wie arp-scan ist nicht im Repo, aber nmap kam vorinstalliert, zeigt nur die IP-Adressen:

nmap -sn 192.168.1.1-254/24 | egrep "scan report" | awk '{print $5}'
 3
Author: zentek,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2017-04-21 16:08:03

Ellaborating auf Anders Larrson Antwort -

#!/bin/bash
function scan ()
{
    for ip in $1.{1..254}; do
        ping -c 1 -W 1 $ip &
    done | sed -nE 's:^.* from ([0-9.]+).*time=(.*s)$:\1 (\2):p'
}

if [ $1 ]; then
    for baseip; do
        scan $baseip
    done
else
    scan 192.168.1
fi
 0
Author: Mathieu CAROFF,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2018-07-06 10:04:06

Dieser Anwswer bestimmt das Subnetz selbst, während Sie es in den anderen Anwwers bereitstellen müssen.

Das Skript verwendet arp -a oder ip -o -f inet addr show, um das Subnetz zu finden.

Ich habe das Skript für @anders-larsson und @mathieu-caroff 's anwwers erstellt. Ich vermeide die Verwendung von 'nmap', aber das Skript ist einfach, nmap zu verwenden.

Grundsätzlich wird $baseip mit Bash-Ersatzmakros im zweiten Teil des Skripts erstellt, wenn in der Befehlszeile kein Parameter angegeben ist. Sonst ist es scannt das bereitgestellte Subnetz (style: 192.1.5 ohne das dritte und letzte Byte der IP).

#!/bin/bash
function scan ()
{
    for ip in $1.{1..254}; do
        ping -c 1 -W 1 $ip &
    done | sed -nE 's:^.* from ([0-9.]+).*time=(.*s)$:\1 (\2):p'
    wait
}

if [ $1 ]; then
    for baseip; do
        scan $baseip
    done
else
    baseip=$(arp -a) && baseip=${baseip%%\)*} && baseip=${baseip##*\(}
    if [ $baseip"" == "" ] ; then
      baseip=$(ip -o -f inet addr show|grep "scope global") && baseip=${baseip##* inet} && baseip=${baseip%%/*}
    fi
    baseip=${baseip%.*}
    scan $baseip 
fi
 0
Author: le_top,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2020-06-08 21:37:12