-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPublicIPTG
More file actions
30 lines (23 loc) · 869 Bytes
/
PublicIPTG
File metadata and controls
30 lines (23 loc) · 869 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/bin/bash
DOM=PON_TU_DOMINIO
HASH=HASH_DE_TELEGRAM
CHAT=NUMEROS_DEL_CHAT
# Obtener la IP del comando ping
ip_ping=$(ping -c 1 $DOM 2>/dev/null | awk -F'[()]' '/PING/{print $2}')
# Obtener la IP pública usando curl
ip_curl=$(curl -s 'https://api.ipify.org')
# Verificar que ambas IPs se obtuvieron correctamente
if [[ -z "$ip_ping" ]]; then
echo "Error: No se pudo obtener la IP mediante ping"
exit 1
fi
if [[ -z "$ip_curl" ]]; then
echo "Error: No se pudo obtener la IP mediante curl"
exit 1
fi
# Comparar las dos IPs
if [[ "$ip_ping" == "$ip_curl" ]]; then
curl -s -X POST https://api.telegram.org/bot"$HASH"/sendMessage -d chat_id="$CHAT" -d text="Las IP coinciden, no hay necesidad de cambio"
else
curl -s -X POST https://api.telegram.org/bot"$HASH"/sendMessage -d chat_id="$CHAT" -d text="Tu IP publica parece ser $ip_curl"
fi