Advertisement
ame824

ssh_access_control.sh

Apr 20th, 2024
922
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.81 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # IP-Adresse des eingehenden SSH-Versuchs erhalten
  4. remote_ip=$(echo $SSH_CONNECTION | awk '{print $1}')
  5.  
  6. # Geo-IP-Informationen von ip-api.com abrufen
  7. geo_info=$(curl -s "http://ip-api.com/json/$remote_ip")
  8.  
  9. # Land aus den Geo-IP-Informationen extrahieren
  10. country=$(echo $geo_info | jq -r '.country')
  11.  
  12. # Liste der erlaubten Länder (Deutschland, Nachbarländer und Spanien)
  13. allowed_countries=("Germany" "France" "Austria" "Switzerland" "Netherlands" "Belgium" "Luxembourg" "Denmark" "Czech Republic" "Poland" "Spain")
  14.  
  15. # Prüfen, ob das Land des eingehenden SSH-Versuchs in der Liste der erlaubten Länder ist
  16. if [[ " ${allowed_countries[@]} " =~ " $country " ]]; then
  17.     echo "SSH access from $country is allowed."
  18.     exit 0
  19. else
  20.     echo "SSH access from $country is blocked."
  21.     exit 1
  22. fi
  23.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement