分页: 1 / 1

udev如何检测连接的SSID

发表于 : 2016-07-22 13:35
smartliu
我有一个家用NAS,希望可以让udev探测,如果连接到了家用wifi上,就自动挂载NAS上的几个分区,否则就不动。该如何写udev规则,望达人指点。

另,如果有其他方式可以做到这个,也请不吝赐教。

Re: udev如何检测连接的SSID

发表于 : 2016-07-22 15:06
poloshiao
希望這一篇 能夠幫上忙
http://unix.stackexchange.com/questions ... ed-in-udev
Auto-run script when Wifi card is plugged in (udev)

如果是 systemd 請另外再貼文

還有問題 請提供 作業系統版本

Re: udev如何检测连接的SSID

发表于 : 2016-07-22 17:57
smartliu
poloshiao 写了:希望這一篇 能夠幫上忙
http://unix.stackexchange.com/questions ... ed-in-udev
Auto-run script when Wifi card is plugged in (udev)

如果是 systemd 請另外再貼文

還有問題 請提供 作業系統版本
感谢回复,不过这篇文章里似乎是说当无线网卡插上时执行脚本,而没有连接到哪个SSID的内容。还有其他资源吗?

我的系统是 Funtoo(OpenRC),没有用 systemd。

Re: udev如何检测连接的SSID

发表于 : 2016-07-22 20:58
vickycq

Re: udev如何检测连接的SSID

发表于 : 2016-07-23 6:38
poloshiao
而没有连接到哪个SSID的内容。还有其他资源吗?
試試
https://wiki.ubuntu.com/OnNetworkConnectionRunScript
Advanced
If you want to do something only when connecting to a certain network you need your scripts to check if the network connection matches. To do this you could check the SSID (the Network Name that Identifies a Network). Here is an example of how this can be achieved :

if [ `iwlist eth0 scanning | grep YourNetworkSSID` ]
then
mount //192.168.0.2/directory /mountpoint -t cifs -o iocharset=utf8,gid=1000,uid=1000,credentials=/root/.smbcredentials,dmask=770,fmask=770
fi

On a wired LAN you could ping a specific Server as follows (look in /etc/hostname, /etc/hosts, /etc/dhcp3/dhcpd.conf for how to configure this) :

...
if [ `ping -c 1 server.local | grep "1 packets transmitted"` ]
...