You've already forked scripts-random
Compare commits
2 Commits
98e3dfd6b7
...
9e0b80ab12
| Author | SHA1 | Date | |
|---|---|---|---|
| 9e0b80ab12 | |||
| 7db4c07fb2 |
@@ -24,16 +24,18 @@ set -euo pipefail
|
||||
|
||||
# Variables de configuración
|
||||
MAX_AGE_DAYS=90 # Número de días de historial a comprobar
|
||||
SLEEP_BETWEEN=1 # Tiempo de espera entre las comprobaciones de IPs
|
||||
THRESHOLD=50 # Umbral de score para considerar una IP sospechosa
|
||||
SLEEP_BETWEEN=1 # Tiempo de espera entre las comprobaciones de IPs
|
||||
|
||||
# Colores para salida
|
||||
COLOR_RED='\e[31m' # Color para mensajes de error
|
||||
COLOR_GREEN='\e[32m' # Color para mensajes exitosos
|
||||
COLOR_YELLOW='\e[33m' # Color para mensajes informativos
|
||||
COLOR_CYAN="\033[36m" # Color para mensajes informativos 1
|
||||
COLOR_YELLOW='\e[33m' # Color para mensajes informativos 2
|
||||
COLOR_BLUE='\e[34m' # Color para títulos y encabezados
|
||||
COLOR_RESET='\e[0m' # Resetea el color al valor predeterminado
|
||||
|
||||
|
||||
# Archivo de log (cambiar la ubicación a un directorio accesible)
|
||||
LOG_FILE="./check_ips_script.log" # Cambiado a un directorio accesible para el usuario
|
||||
|
||||
@@ -54,22 +56,10 @@ function log_message() {
|
||||
echo "$(date '+%Y-%m-%d %H:%M:%S') - $message" >>"$LOG_FILE"
|
||||
}
|
||||
|
||||
# Función para imprimir títulos con formato y colores
|
||||
function print_title {
|
||||
local title="$1"
|
||||
local title_length=${#title}
|
||||
local total_length=22
|
||||
local margin_length=$(((total_length - title_length - 4) / 2))
|
||||
local left_padding=$((margin_length))
|
||||
local right_padding=$((margin_length + (title_length % 2)))
|
||||
|
||||
echo -e "${COLOR_BLUE}\n$(printf '#%.0s' $(seq 1 $left_padding))#### $title ####$(printf '#%.0s' $(seq 1 $right_padding))\n${COLOR_RESET}"
|
||||
}
|
||||
|
||||
# Comprobación de dependencias necesarias
|
||||
for cmd in jq curl; do
|
||||
if ! command -v "$cmd" >/dev/null 2>&1; then
|
||||
echo -e "${COLOR_RED}Error: '$cmd' no está instalado. Instálalo y vuelve a ejecutar.${COLOR_RESET}" >&2
|
||||
echo -e "${COLOR_RED}[!] Error: '$cmd' no está instalado. Instálalo y vuelve a ejecutar.${COLOR_RESET}" >&2
|
||||
log_message "Error: '$cmd' no está instalado."
|
||||
exit 2
|
||||
fi
|
||||
@@ -80,9 +70,9 @@ log_message "Iniciando el script de comprobación de IPs."
|
||||
# Leer API_KEY desde variable de entorno o pedir al usuario
|
||||
API_KEY="${API_KEY_ipabuse:-}"
|
||||
if [[ -z "$API_KEY" ]]; then
|
||||
read -rp "Introduce tu API key de AbuseIPDB: " API_KEY
|
||||
read -rp "[+] Introduce tu API key de AbuseIPDB: " API_KEY
|
||||
if [[ -z "$API_KEY" ]]; then
|
||||
echo -e "${COLOR_RED}Error: la API key es obligatoria.${COLOR_RESET}" >&2
|
||||
echo -e "${COLOR_RED}[!] Error: la API key es obligatoria.${COLOR_RESET}" >&2
|
||||
log_message "Error: No se proporcionó API Key."
|
||||
exit 1
|
||||
fi
|
||||
@@ -91,10 +81,10 @@ fi
|
||||
# Leer lista de IPs desde variable de entorno o pedir al usuario
|
||||
IPS_LIST="${IPS_LIST_abuseipdb:-}"
|
||||
if [[ -z "$IPS_LIST" ]]; then
|
||||
echo -e "${COLOR_YELLOW}Introduce el listado de IPs (una por línea). Finaliza con Ctrl+D:${COLOR_RESET}"
|
||||
echo -e "${COLOR_YELLOW}[+] Introduce el listado de IPs (una por línea). Finaliza con Ctrl+D:${COLOR_RESET}"
|
||||
IPS_LIST="$(cat)"
|
||||
if [[ -z "$IPS_LIST" ]]; then
|
||||
echo -e "${COLOR_RED}Error: no se proporcionaron IPs.${COLOR_RESET}" >&2
|
||||
echo -e "${COLOR_RED}[!] Error: no se proporcionaron IPs.${COLOR_RESET}" >&2
|
||||
log_message "Error: No se proporcionaron IPs."
|
||||
exit 1
|
||||
fi
|
||||
@@ -103,15 +93,18 @@ fi
|
||||
# Convertir lista de IPs multilínea a array para procesar cada IP
|
||||
mapfile -t iterator <<< "$IPS_LIST"
|
||||
|
||||
# Imprimir el título principal del script
|
||||
print_title "Comprobando IPs en AbuseIPDB"
|
||||
# Imprimir el título principal del script e información
|
||||
echo -e "${COLOR_BLUE}\n[i] Comprobando IPs en AbuseIPDB${COLOR_RESET}"
|
||||
echo -e "${COLOR_CYAN} Puedes cambiar algunos parámetros en el script:${COLOR_RESET}"
|
||||
echo -e "${COLOR_CYAN} - Días de historial a comprobar: (MAX_AGE_DAYS=90)${COLOR_RESET}"
|
||||
echo -e "${COLOR_CYAN} - Umbral de score para considerar una IP sospechosa: (THRESHOLD=50)\n${COLOR_RESET}"
|
||||
|
||||
# Procesar cada IP
|
||||
for ip in "${iterator[@]}"; do
|
||||
ip=$(echo "$ip" | xargs) # Eliminar espacios en blanco extra
|
||||
[[ -z "$ip" ]] && continue # Saltar si la IP está vacía
|
||||
|
||||
echo -e "${COLOR_BLUE}=== IP: $ip ===${COLOR_RESET}"
|
||||
echo -e "${COLOR_BLUE}[i] Checkeando IP: $ip${COLOR_RESET}"
|
||||
|
||||
# Hacer la solicitud a la API de AbuseIPDB
|
||||
resp=$(curl -sS -G "https://api.abuseipdb.com/api/v2/check" \
|
||||
@@ -123,14 +116,14 @@ for ip in "${iterator[@]}"; do
|
||||
|
||||
# Controlar si no se obtiene respuesta de la API
|
||||
if [[ -z "$resp" ]]; then
|
||||
echo -e "${COLOR_RED}❌ Sin respuesta de la API.${COLOR_RESET}"
|
||||
echo -e "${COLOR_RED}[!] Sin respuesta de la API.${COLOR_RESET}"
|
||||
log_message "Error: No se recibió respuesta para la IP $ip."
|
||||
continue
|
||||
fi
|
||||
|
||||
# Verificar si hay errores en la respuesta de la API
|
||||
if echo "$resp" | jq -e '.errors? != null' >/dev/null; then
|
||||
echo -e "${COLOR_RED}❌ Error de API:${COLOR_RESET}"
|
||||
echo -e "${COLOR_RED}[!] Error de API:${COLOR_RESET}"
|
||||
echo "$resp" | jq '.errors'
|
||||
log_message "Error de API para la IP $ip: $(echo "$resp" | jq -r '.errors')"
|
||||
continue
|
||||
@@ -145,16 +138,21 @@ for ip in "${iterator[@]}"; do
|
||||
usage=$(echo "$resp" | jq -r '.data.usageType // "N/A"')
|
||||
|
||||
# Mostrar los resultados de la IP
|
||||
echo " País: $country"
|
||||
echo " ISP: $isp"
|
||||
echo " Uso: $usage"
|
||||
echo " Total reportes: $totalReports"
|
||||
echo " Último reporte: $lastReported"
|
||||
echo " Score abuso: $abuseScore"
|
||||
echo -e "${COLOR_CYAN}[+] País:${COLOR_RESET} ${COLOR_YELLOW}$country${COLOR_RESET}"
|
||||
echo -e "${COLOR_CYAN}[+] ISP:${COLOR_RESET} ${COLOR_YELLOW}$isp${COLOR_RESET}"
|
||||
echo -e "${COLOR_CYAN}[+] Uso:${COLOR_RESET} ${COLOR_YELLOW}$usage${COLOR_RESET}"
|
||||
echo -e "${COLOR_CYAN}[+] Total reportes:${COLOR_RESET} ${COLOR_YELLOW}$totalReports${COLOR_RESET}"
|
||||
echo -e "${COLOR_CYAN}[+] Último reporte:${COLOR_RESET} ${COLOR_YELLOW}$lastReported${COLOR_RESET}"
|
||||
|
||||
if (( abuseScore >= 50 )); then
|
||||
echo -e "${COLOR_CYAN}[+] Score abuso:${COLOR_RESET} ${COLOR_RED}$abuseScore${COLOR_RESET}"
|
||||
else
|
||||
echo -e "${COLOR_CYAN}[+] Score abuso:${COLOR_RESET} ${COLOR_GREEN}$abuseScore${COLOR_RESET}"
|
||||
fi
|
||||
|
||||
# Contar categorías de ataques reportados
|
||||
if (( totalReports > 0 )); then
|
||||
echo -e "${COLOR_YELLOW} Categorías reportadas:${COLOR_RESET}"
|
||||
echo -e "${COLOR_CYAN}[+] Categorías reportadas:${COLOR_RESET}"
|
||||
declare -A category_map=(
|
||||
[3]="Fraude en pedidos"
|
||||
[4]="Ataque DDoS"
|
||||
@@ -182,17 +180,17 @@ for ip in "${iterator[@]}"; do
|
||||
# Mostrar las categorías de ataque reportadas
|
||||
echo "$resp" | jq -r '.data.reports[].categories[]' | sort | uniq -c | sort -rn | while read -r count cat; do
|
||||
description="${category_map[$cat]:-Desconocida}"
|
||||
echo " - $description (Categoría $cat): $count veces"
|
||||
done
|
||||
printf " ${COLOR_CYAN}[+] %-20s ${COLOR_RESET} ${COLOR_YELLOW}%s veces${COLOR_RESET}\n" "$description:" "$count"
|
||||
done
|
||||
fi
|
||||
|
||||
# Evaluar si la IP es sospechosa en base al score
|
||||
if (( abuseScore >= THRESHOLD )); then
|
||||
echo -e "${COLOR_RED} 🔴 Resultado: SOSPECHOSA (score >= $THRESHOLD)${COLOR_RESET}"
|
||||
log_message "IP: $ip - Resultado: SOSPECHOSA (score >= $THRESHOLD)"
|
||||
echo -e "${COLOR_RED}\n🔴 Resultado: La IP $ip es SOSPECHOSA (score $abuseScore >= $THRESHOLD)${COLOR_RESET}"
|
||||
log_message "IP: $ip - Resultado: SOSPECHOSA (score $abuseScore >= $THRESHOLD)"
|
||||
else
|
||||
echo -e "${COLOR_GREEN} 🟢 Resultado: OK / No sospechosa (score < $THRESHOLD)${COLOR_RESET}"
|
||||
log_message "IP: $ip - Resultado: OK / No sospechosa (score < $THRESHOLD)"
|
||||
echo -e "${COLOR_GREEN}\n🟢 Resultado: La IP $ip no es sospechosa (score $abuseScore < $THRESHOLD)${COLOR_RESET}"
|
||||
log_message "IP: $ip - Resultado: OK / No sospechosa (score $abuseScore < $THRESHOLD)"
|
||||
fi
|
||||
|
||||
echo
|
||||
@@ -200,5 +198,5 @@ for ip in "${iterator[@]}"; do
|
||||
done
|
||||
|
||||
# Mensaje final de éxito
|
||||
echo -e "${COLOR_GREEN}✅ Comprobación finalizada.${COLOR_RESET}"
|
||||
echo -e "${COLOR_BLUE}[i] Comprobación finalizada\n${COLOR_RESET}"
|
||||
log_message "El script se ejecutó correctamente."
|
||||
|
||||
28
02_perl/pregunta.pl
Normal file
28
02_perl/pregunta.pl
Normal file
@@ -0,0 +1,28 @@
|
||||
#!/usr/bin/perl
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
# Mostrar el nombre de usuario
|
||||
print "Hola ", `whoami`;
|
||||
|
||||
# Bucle infinito
|
||||
while (1) {
|
||||
# Leer la respuesta del usuario
|
||||
print "dime si o no (s/n) ";
|
||||
my $respuesta = <STDIN>;
|
||||
chomp($respuesta); # Eliminar el salto de línea
|
||||
|
||||
# Evaluar la respuesta
|
||||
if ($respuesta =~ /^[sS]$/) {
|
||||
print "La respuesta es sí\n";
|
||||
last; # Salir del bucle
|
||||
}
|
||||
elsif ($respuesta =~ /^[nN]$/) {
|
||||
print "La respuesta es No\n";
|
||||
exit; # Salir del script
|
||||
}
|
||||
else {
|
||||
print "Que me estas container\n";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user