Skip to content

Instantly share code, notes, and snippets.

@dev-ir
Last active June 20, 2024 22:35
Show Gist options
  • Save dev-ir/4ec5873cbff302d3b1e0d9e85a6e95c5 to your computer and use it in GitHub Desktop.
Save dev-ir/4ec5873cbff302d3b1e0d9e85a6e95c5 to your computer and use it in GitHub Desktop.
icmp-status-manager
#!/bin/bash
#add color for text
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
plain='\033[0m'
NC='\033[0m' # No Color
# Get server IP
SERVER_IP=$(hostname -I | awk '{print $1}')
# Fetch server country using ip-api.com
SERVER_COUNTRY=$(curl -sS "http://ip-api.com/json/$SERVER_IP" | jq -r '.country')
# Fetch server isp using ip-api.com
SERVER_ISP=$(curl -sS "http://ip-api.com/json/$SERVER_IP" | jq -r '.isp')
status=$(cat /proc/sys/net/ipv4/icmp_echo_ignore_all)
status=$(cat /proc/sys/net/ipv4/icmp_echo_ignore_all)
if [ "$status" -eq 0 ]; then
status_ping="Enabled"
else
status_ping="Disable"
fi
cur_dir=$(pwd)
# check root
[[ $EUID -ne 0 ]] && echo -e "${RED}Fatal error: ${plain} Please run this script with root privilege \n " && exit 1
init(){
clear
echo "+-------------------------------------------------------------------------------------------------+"
echo "| |"
echo "| ####### ####### ## ### ####### ####### ####### ###### ####### ## ### ####### |"
echo "| ### ## ### ####### ## ## ## ### ## ## ### ## ### ## |"
echo "| ### ## ### ####### ## ## ####### ### ## ## ### ## ### ####### |"
echo "| ### ## ### ### ####### ## ### ####### ### ## ### ## |"
echo "| ### ## ## ## ### ### ### ## ### ### ## ### ## ### ### ## |"
echo "| ### ## ## ## ### ### ### ## ### ### ## ### ## ### ### ## |"
echo "| ####### ####### ## ### ### ####### ### ### ## ### ####### ####### |"
echo "| |"
echo "+-------------------------------------------------------------------------------------------------+"
echo -e "${GREEN}Server Country:${NC} $SERVER_COUNTRY"
echo -e "${GREEN}Server IP:${NC} $SERVER_IP"
echo -e "${GREEN}Server ISP:${NC} $SERVER_ISP"
echo -e "${GREEN}Server Ping:${NC} $status_ping"
echo "+-------------------------------------------------------------------------------------------------+"
echo -e "${GREEN}Please choose an option:${NC}"
echo "+--------------------------------------------------------------------------------------+"
echo -e "${BLUE}| 1 - Enable ICMP"
echo -e "${BLUE}| 2 - Disable ICMP"
echo -e "${BLUE}| 0 - Exit"
echo "+--------------------------------------------------------------------------------------+"
echo -e "\033[0m"
read -p "Enter option number: " choice
case $choice in
1)
sudo sysctl -w net.ipv4.icmp_echo_ignore_all=0
echo "ICMP is enabled."
;;
2)
sudo sysctl -w net.ipv4.icmp_echo_ignore_all=1
echo "ICMP is disabled."
;;
0)
echo -e "${GREEN}Exiting program...${NC}"
exit 0
;;
*)
echo "Not valid"
return_home
;;
esac
}
return_home(){
bash <(curl -Ls https://raw.githubusercontent.com/dev-ir/dev-tunnel/master/multi-tunnel.sh)
}
init
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment