Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- Version='0.2.10'
- # Put your wifi interface here
- interface='wlp3s0'
- # Put the ip to ping here (google by default)
- # Use IPS because some parameters of the shell only work with ip's
- # If not the shell will run slow (-w maxping on ping)
- host='google.com'
- maxping=2
- # Reset
- NC='\033[0m' # Text Reset
- # Regular Colors
- Red='\033[0;31m' # Red
- # Bold
- BRed='\033[1;31m' # Red
- BGreen='\033[1;32m' # Green
- BYellow='\033[1;33m' # Yellow
- BCyan='\033[1;36m' # Cyan
- echo -e "${BGreen}____________________________________________________________${NC}"
- echo -e "Version ${BGreen}${Version}${NC}"
- echo -e "Made with love by"
- echo -e "${BCyan}
- ▄▄▄·▪ ▐ ▄ ▄▄
- ▐█ ▄███ ▪ •█▌▐█▪ ██▌
- ██▀·▐█· ▄█▀▄ ▐█▐▐▌ ▄█▀▄ ▐█·
- ▐█▪·•▐█▌▐█▌.▐▌██▐█▌▐█▌.▐▌.▀
- .▀ ▀▀▀ ▀█▄▀▪▀▀ █▪ ▀█▄▀▪ ▀
- ${NC}"
- echo -e "Please run with ${BRed}sudo${NC} and make it executable with ${BRed}chmod +x${NC}"
- echo -e "Do ${BRed}iwconfig${NC} and modify the script with your wifi interface"
- echo -e "${BGreen}____________________________________________________________${NC}"
- while true;
- do
- echo -e "${BCyan}CHECKING ${NC}network availability"
- echo -e "${Red}------------------------------------------------${NC}"
- sleep 5
- ping -q -W ${maxping} -c1 ${host} > /ping.$
- if [ $? -eq 0 ]
- then
- echo -e "The connection is ${BGreen}OK${NC}"
- echo -e "${Red}------------------------------------------------${NC}"
- else
- ping -q -W ${maxping} -c1 ${host} > /ping.$
- if [ $? -eq 0 ]
- then
- echo -e "Packet lost but now is ${BYellow}'OK'${NC}"
- echo -e "${Red}------------------------------------------------${NC}"
- else
- echo -e "Connection ${BRed}LOST${NC}"
- echo -e "${Red}------------------------------------------------${NC}"
- echo -e "${BCyan}Restarting ${NC}wifi"
- echo -e "${Red}------------------------------------------------${NC}"
- echo -e "${BCyan}Wifi ${BRed}off${NC}"
- nmcli n off
- # nmcli radio wifi off
- sudo iwconfig ${interface} txpower off
- sleep 1
- echo -e "${BCyan}Wifi ${BGreen}on${NC}"
- sudo iwconfig ${interface} txpower on
- sleep 3
- # nmcli n is deprecated, now we use nmcli radio wifi on, same for nmcli n off
- nmcli n on
- # nmcli radio wifi on
- sleep 10
- ping -q -W ${maxping} -c1 ${host} > /ping.$
- if [ $? -eq 0 ]
- then
- echo -e "${BGreen}SUCCESS!${NC}"
- else
- echo -e "${BRed}Attempting last resource...${NC}"
- echo -e "${BGreen}___________________________________________${NC}"
- echo -e "${BCyan}RESTARTING ${NC}network manager service from systemctl"
- sudo /bin/systemctl restart network-manager.service
- sleep 4
- fi
- fi
- fi
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement