GeekHub

Linux查询网段内所有设备

方法一:使用nmap命令

举例说明,我的计算机在192.168.199.x网段下的地址为192.168.199.234,网段子关掩码为255.255.255.0(24位子管掩码),那么查询我的计算机在192.168.199.x下的所有设备则使用如下命令

nmap -sn 192.168.199.0/24

返回数据:

Starting Nmap 7.01 ( https://nmap.org ) at 2020-03-31 11:02 CST
Nmap scan report for Hiwifi.lan (192.168.199.1)
Host is up (0.00077s latency).
Nmap scan report for chuangmi_camera_ipc009.lan (192.168.199.101)
Host is up (0.0012s latency).
Nmap scan report for HUAWEI_Mate_20.lan (192.168.199.111)
Host is up (0.087s latency).
Nmap scan report for chuangmi-plug-v3_miapDC70.lan (192.168.199.140)
Host is up (0.0030s latency).
Nmap scan report for ryan-ThinkPad-X270.lan (192.168.199.227)
Host is up (0.0012s latency).
Nmap scan report for ryan-OptiPlex-7040.lan (192.168.199.234)
Host is up (0.00026s latency).
Nmap done: 256 IP addresses (6 hosts up) scanned in 2.74 seconds

方法二:使用nbtscan命令

通过nbtscan可以直接扫描网段内全部设备,方法类似nmap(nbtscan需要sudo权限):

sudo nbtscan 192.168.199.0/24

返回信息(只返回了网段内的计算机设备,我的手机和远程摄像头都没有扫描出来,原因不明,可能因为设备网络配置的问题):

Doing NBT name scan for addresses from 192.168.199.0/24

IP address       NetBIOS Name     Server    User             MAC address      
------------------------------------------------------------------------------
192.168.199.0	Sendto failed: Permission denied
192.168.199.234  RYAN-OPTIPLEX-7  <server>  RYAN-OPTIPLEX-7  00:00:00:00:00:00
192.168.199.255	Sendto failed: Permission denied
192.168.199.227  RYAN-THINKPAD-X  <server>  RYAN-THINKPAD-X  00:00:00:00:00:00

还可以搜索网段内指定IP地址段内的设备:

sudo nbtscan 192.168.199.100-230

返回信息:

Doing NBT name scan for addresses from 192.168.199.100-230

IP address       NetBIOS Name     Server    User             MAC address      
------------------------------------------------------------------------------
192.168.199.227  RYAN-THINKPAD-X  <server>  RYAN-THINKPAD-X  00:00:00:00:00:00

以上就是Linux下查询网段内所有设备IP的方法,综合而言,根据我日常使用的经验,nmap不容易遗漏IP地址,但是查询到的信息没有nbtscan丰富直观,所以我比较推荐两种方法同时使用。

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注