我有一个树莓派,但是没有显示器。
已经开启了sshd。所以ssh可以登录。
但是必须知道ip地址。
比如我的手机开个热点,我的笔记本和树莓派都进入到我的手机热点的网络,我就可以使用笔记本ssh到树莓派。因为我可以在手机上看到连接的树莓派的ip地址。
那么假如树莓派要切换一个新的WIFI网络,该怎么知道呢分配的ip地址呢?
假如看不到路由器的连接设备信息。
但是我可以用笔记本连接同一个WIFI。
更新:
非常感谢各位,学到很多。
目前发现利用树莓派的特性似乎最方便。
ssh <username>@<hostname>.local 可以直接登录。当然这是基于zeroconfig技术的。
例如我的情况:
? ~/ ssh pi@raspberrypi4.local
The authenticity of host 'raspberrypi4.local (fe80::a72:9aa9:cd8b:7f14%en0)' can't be established.
ECDSA key fingerprint is SHA256:fgC9ed3ovizkNw8NjTwPRHY9y1OYFUBgUqfEQjd4IaE.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'raspberrypi4.local,fe80::a72:9aa9:cd8b:7f14%en0' (ECDSA) to the list of known hosts.
pi@raspberrypi4.local's password:
Linux raspberrypi4 4.19.75-v7l+ #1270 SMP Tue Sep 24 18:51:41 BST 2019 armv7l
The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Fri May 1 17:20:21 2020 from 192.168.43.82
? ~ ipme
192.168.0.107
更新2:
综合各位提的fping,arp
第二种方法我觉得也可以。先fping一个网段,然后arp查mac地址。
>fping -g -r 1 192.168.0.0/24
192.168.0.1 is alive
192.168.0.110 is alive
192.168.0.106 is alive
192.168.0.104 is alive
192.168.0.101 is alive
192.168.0.107 is alive
192.168.0.103 is alive
192.168.0.108 is alive
192.168.0.2 is unreachable
...
> arp -a
localhost (192.168.0.1) at f4:83:cd:10:37:95 on en0 ifscope [ethernet]
localhost (192.168.0.101) at c4:86:e9:13:51:cf on en0 ifscope [ethernet]
localhost (192.168.0.103) at c8:93:46:35:16:1c on en0 ifscope [ethernet]
localhost (192.168.0.104) at 88:2d:53:2f:84:ee on en0 ifscope [ethernet]
localhost (192.168.0.105) at 48:e:ec:92:d5:44 on en0 ifscope [ethernet]
localhost (192.168.0.106) at ac:d5:64:d2:71:6f on en0 ifscope [ethernet]
localhost (192.168.0.107) at dc:a6:32:4c:96:54 on en0 ifscope [ethernet] <-- 这里
localhost (192.168.0.108) at b8:27:eb:9:2a:63 on en0 ifscope [ethernet]
localhost (192.168.0.110) at d0:a6:37:ed:e9:c5 on en0 ifscope permanent [ethernet]
localhost (192.168.0.255) at ff:ff:ff:ff:ff:ff on en0 ifscope [ethernet]
更新3:
第三种方法用nmap,很好,甚至不需要记mac也能看出来
~/ sudo nmap -sP -PI -PT 192.168.0.1/24
Starting Nmap 7.80 (
https://nmap.org ) at 2020-05-02 12:53 CST
Nmap scan report for localhost (192.168.0.1)
Host is up (0.0017s latency).
。。。
MAC Address: F4:83:CD:10:37:95 (Tp-link Technologies)
Nmap scan report for localhost (192.168.0.107) <-- 这里
Host is up (0.18s latency).
MAC Address: DC:A6:32:4C:96:54 (Raspberry Pi Trading)
Nmap scan report for localhost (192.168.0.108)
Host is up (0.080s latency).
MAC Address: B8:27:EB:09:2A:63 (Raspberry Pi Foundation)
※ 修改:·littleSram 于 May 3 07:18:54 2020 修改本文·[FROM: 114.249.20.*]
※ 来源:·水木社区
http://m.newsmth.net·[FROM: 114.249.20.*]
修改:littleSram FROM 114.249.20.*
FROM 114.249.20.*