Wifi断线自动连接
#!/bin/sh # ARGUMENTS := <ifname> ([+|-]<setting>.<property> <value>)+ # Modify one or more properties currently active on the device without modifying # the connection profile. The changes have immediate effect. For multi-valued # properties you can use optional '+' or '-' prefix to the property name. # The '+' sign allows appending items instead of overwriting the whole value. # The '-' sign allows removing selected items instead of the whole value. # Examples: # nmcli dev mod em1 ipv4.method manual ipv4.addr "192.168.1.2/24, 10.10.1.5/8" # nmcli dev mod em1 +ipv4.dns 8.8.4.4 # nmcli dev mod em1 -ipv4.dns 1 # nmcli dev mod em1 -ipv6.addr "abbe::cafe/56" # Usage: nmcli connection { COMMAND | help } # COMMAND := { show | up | down | add | modify | clone | edit | delete | monitor | reload | load | import | export } # show [--active] [--order <order spec>] # show [--active] [id | uuid | path | apath] <ID> ... # up [[id | uuid | path] <ID>] [ifname <ifname>] [ap <BSSID>] [passwd-file <file with passwords>] # down [id | uuid | path | apath] <ID> ... # add COMMON_OPTIONS TYPE_SPECIFIC_OPTIONS SLAVE_OPTIONS IP_OPTIONS [-- ([+|-]<setting>.<property> <value>)+] # modify [--temporary] [id | uuid | path] <ID> ([+|-]<setting>.<property> <value>)+ # clone [--temporary] [id | uuid | path ] <ID> <new name> # edit [id | uuid | path] <ID> # edit [type <new_con_type>] [con-name <new_con_name>] # delete [id | uuid | path] <ID> # monitor [id | uuid | path] <ID> ... # reload # load <filename> [ <filename>... ] # import [--temporary] type <type> file <file to import> # export [id | uuid | path] <ID> [<output file>] # Usage: nmcli device wifi { ARGUMENTS | help } # Perform operation on Wi-Fi devices. # ARGUMENTS := [list [ifname <ifname>] [bssid <BSSID>]] # List available Wi-Fi access points. The 'ifname' and 'bssid' options can be # used to list APs for a particular interface, or with a specific BSSID. # ARGUMENTS := connect <(B)SSID> [password <password>] [wep-key-type key|phrase] [ifname <ifname>] # [bssid <BSSID>] [name <name>] [private yes|no] [hidden yes|no] # Connect to a Wi-Fi network specified by SSID or BSSID. The command creates # a new connection and then activates it on a device. This is a command-line # counterpart of clicking an SSID in a GUI client. The command always creates # a new connection and thus it is mainly useful for connecting to new Wi-Fi # networks. If a connection for the network already exists, it is better to # bring up the existing profile as follows: nmcli con up id <name>. Note that # only open, WEP and WPA-PSK networks are supported at the moment. It is also # assumed that IP configuration is obtained via DHCP. # ARGUMENTS := hotspot [ifname <ifname>] [con-name <name>] [ssid <SSID>] # [band a|bg] [channel <channel>] [password <password>] # Create a Wi-Fi hotspot. Use 'connection down' or 'device disconnect' # to stop the hotspot. # Parameters of the hotspot can be influenced by the optional parameters: # ifname - Wi-Fi device to use # con-name - name of the created hotspot connection profile # ssid - SSID of the hotspot # band - Wi-Fi band to use # channel - Wi-Fi channel to use # password - password to use for the hotspot # ARGUMENTS := rescan [ifname <ifname>] [[ssid <SSID to scan>] ...] # Request that NetworkManager immediately re-scan for available access points. # NetworkManager scans Wi-Fi networks periodically, but in some cases it might # be useful to start scanning manually. 'ssid' allows scanning for a specific # SSID, which is useful for APs with hidden SSIDs. More 'ssid' parameters can be # given. Note that this command does not show the APs, # use 'nmcli device wifi list' for that. while : do gateway=$(route -n | grep wlan0 | grep UG | awk '{print $2}') if [ -z $gateway ]; then echo "the gateway is null, wlan0 connecting..." nmcli conn up MySSID else ping -c 3 -I wlan0 -s 8 $gateway >/dev/null 2>&1 if [ $? = 0 ]; then echo "wifi is connected" else echo "wlan0 connecting..." nmcli conn up MySSID fi fi sleep 150 done
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 零经验选手,Compose 一天开发一款小游戏!
· 通过 API 将Deepseek响应流式内容输出到前端
· AI Agent开发,如何调用三方的API Function,是通过提示词来发起调用的吗