portwg.sh 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/bin/bash
  2. # SL
  3. # ==========================================
  4. # Color
  5. RED='\033[0;31m'
  6. NC='\033[0m'
  7. GREEN='\033[0;32m'
  8. ORANGE='\033[0;33m'
  9. BLUE='\033[0;34m'
  10. PURPLE='\033[0;35m'
  11. CYAN='\033[0;36m'
  12. LIGHT='\033[0;37m'
  13. # ==========================================
  14. # Getting
  15. MYIP=$(wget -qO- ipinfo.io/ip);
  16. echo "Checking VPS"
  17. IZIN=$( curl ipinfo.io/ip | grep $MYIP )
  18. if [ $MYIP = $MYIP ]; then
  19. echo -e "${NC}${GREEN}Permission Accepted...${NC}"
  20. else
  21. echo -e "${NC}${RED}Permission Denied!${NC}";
  22. echo -e "${NC}${LIGHT}Fuck You!!"
  23. exit 0
  24. fi
  25. NIC=$(ip -o $ANU -4 route show to default | awk '{print $5}');
  26. clear
  27. wg="$(cat ~/log-install.txt | grep -i Wireguard | cut -d: -f2|sed 's/ //g')"
  28. echo -e "======================================"
  29. echo -e ""
  30. echo -e "Change Port $wg"
  31. echo -e ""
  32. echo -e "======================================"
  33. read -p "New Port Wireguard : " wg2
  34. if [ -z $wg2 ]; then
  35. echo "Please Input Port"
  36. exit 0
  37. fi
  38. cek=$(netstat -nutlp | grep -w $wg2)
  39. if [[ -z $cek ]]; then
  40. sed -i "s/$wg/$wg2/g" /etc/wireguard/wg0.conf
  41. sed -i "s/$wg/$wg2/g" /etc/wireguard/params
  42. sed -i "s/ - Wireguard : $wg/ - Wireguard : $wg2/g" /root/log-install.txt
  43. iptables -D INPUT -i $NIC -p udp --dport $wg -j ACCEPT
  44. iptables -I INPUT -i $NIC -p udp --dport $wg2 -j ACCEPT
  45. iptables-save > /etc/iptables.up.rules
  46. iptables-restore -t < /etc/iptables.up.rules
  47. netfilter-persistent save > /dev/null
  48. netfilter-persistent reload > /dev/null
  49. systemctl reload wg-quick@wg0 > /dev/null
  50. echo -e "\e[032;1mPort $wg2 modified successfully\e[0m"
  51. else
  52. echo "Port $wg2 is used"
  53. fi