chore: layout scripts/monitoring + tor configs; host README
This commit is contained in:
parent
5920296ae4
commit
4180ca44c6
12 changed files with 1007 additions and 0 deletions
249
scripts/monitoring/countries.txt
Executable file
249
scripts/monitoring/countries.txt
Executable file
|
|
@ -0,0 +1,249 @@
|
|||
AF=Afghanistan
|
||||
AX=Åland Islands
|
||||
AL=Albania
|
||||
DZ=Algeria
|
||||
AS=American Samoa
|
||||
AD=Andorra
|
||||
AO=Angola
|
||||
AI=Anguilla
|
||||
AQ=Antarctica
|
||||
AG=Antigua and Barbuda
|
||||
AR=Argentina
|
||||
AM=Armenia
|
||||
AW=Aruba
|
||||
AU=Australia
|
||||
AT=Austria
|
||||
AZ=Azerbaijan
|
||||
BS=Bahamas
|
||||
BH=Bahrain
|
||||
BD=Bangladesh
|
||||
BB=Barbados
|
||||
BY=Belarus
|
||||
BE=Belgium
|
||||
BZ=Belize
|
||||
BJ=Benin
|
||||
BM=Bermuda
|
||||
BT=Bhutan
|
||||
BO=Bolivia
|
||||
BQ=Bonaire, Sint Eustatius and Saba
|
||||
BA=Bosnia and Herzegovina
|
||||
BW=Botswana
|
||||
BV=Bouvet Island
|
||||
BR=Brazil
|
||||
IO=British Indian Ocean Territory
|
||||
BN=Brunei Darussalam
|
||||
BG=Bulgaria
|
||||
BF=Burkina Faso
|
||||
BI=Burundi
|
||||
KH=Cambodia
|
||||
CM=Cameroon
|
||||
CA=Canada
|
||||
CV=Cabo Verde
|
||||
KY=Cayman Islands
|
||||
CF=Central African Republic
|
||||
TD=Chad
|
||||
CL=Chile
|
||||
CN=China
|
||||
CX=Christmas Island
|
||||
CC=Cocos (Keeling) Islands
|
||||
CO=Colombia
|
||||
KM=Comoros
|
||||
CG=Congo
|
||||
CD=Congo (DRC)
|
||||
CK=Cook Islands
|
||||
CR=Costa Rica
|
||||
CI=Côte d'Ivoire
|
||||
HR=Croatia
|
||||
CU=Cuba
|
||||
CW=Curaçao
|
||||
CY=Cyprus
|
||||
CZ=Czechia
|
||||
DK=Denmark
|
||||
DJ=Djibouti
|
||||
DM=Dominica
|
||||
DO=Dominican Republic
|
||||
EC=Ecuador
|
||||
EG=Egypt
|
||||
SV=El Salvador
|
||||
GQ=Equatorial Guinea
|
||||
ER=Eritrea
|
||||
EE=Estonia
|
||||
SZ=Eswatini
|
||||
ET=Ethiopia
|
||||
FK=Falkland Islands
|
||||
FO=Faroe Islands
|
||||
FJ=Fiji
|
||||
FI=Finland
|
||||
FR=France
|
||||
GF=French Guiana
|
||||
PF=French Polynesia
|
||||
TF=French Southern Territories
|
||||
GA=Gabon
|
||||
GM=Gambia
|
||||
GE=Georgia
|
||||
DE=Germany
|
||||
GH=Ghana
|
||||
GI=Gibraltar
|
||||
GR=Greece
|
||||
GL=Greenland
|
||||
GD=Grenada
|
||||
GP=Guadeloupe
|
||||
GU=Guam
|
||||
GT=Guatemala
|
||||
GG=Guernsey
|
||||
GN=Guinea
|
||||
GW=Guinea-Bissau
|
||||
GY=Guyana
|
||||
HT=Haiti
|
||||
HM=Heard Island and McDonald Islands
|
||||
VA=Holy See
|
||||
HN=Honduras
|
||||
HK=Hong Kong
|
||||
HU=Hungary
|
||||
IS=Iceland
|
||||
IN=India
|
||||
ID=Indonesia
|
||||
IR=Iran
|
||||
IQ=Iraq
|
||||
IE=Ireland
|
||||
IM=Isle of Man
|
||||
IL=Israel
|
||||
IT=Italy
|
||||
JM=Jamaica
|
||||
JP=Japan
|
||||
JE=Jersey
|
||||
JO=Jordan
|
||||
KZ=Kazakhstan
|
||||
KE=Kenya
|
||||
KI=Kiribati
|
||||
KP=North Korea
|
||||
KR=South Korea
|
||||
KW=Kuwait
|
||||
KG=Kyrgyzstan
|
||||
LA=Laos
|
||||
LV=Latvia
|
||||
LB=Lebanon
|
||||
LS=Lesotho
|
||||
LR=Liberia
|
||||
LY=Libya
|
||||
LI=Liechtenstein
|
||||
LT=Lithuania
|
||||
LU=Luxembourg
|
||||
MO=Macao
|
||||
MG=Madagascar
|
||||
MW=Malawi
|
||||
MY=Malaysia
|
||||
MV=Maldives
|
||||
ML=Mali
|
||||
MT=Malta
|
||||
MH=Marshall Islands
|
||||
MQ=Martinique
|
||||
MR=Mauritania
|
||||
MU=Mauritius
|
||||
YT=Mayotte
|
||||
MX=Mexico
|
||||
FM=Micronesia
|
||||
MD=Moldova
|
||||
MC=Monaco
|
||||
MN=Mongolia
|
||||
ME=Montenegro
|
||||
MS=Montserrat
|
||||
MA=Morocco
|
||||
MZ=Mozambique
|
||||
MM=Myanmar
|
||||
NA=Namibia
|
||||
NR=Nauru
|
||||
NP=Nepal
|
||||
NL=Netherlands
|
||||
NC=New Caledonia
|
||||
NZ=New Zealand
|
||||
NI=Nicaragua
|
||||
NE=Niger
|
||||
NG=Nigeria
|
||||
NU=Niue
|
||||
NF=Norfolk Island
|
||||
MK=North Macedonia
|
||||
MP=Northern Mariana Islands
|
||||
NO=Norway
|
||||
OM=Oman
|
||||
PK=Pakistan
|
||||
PW=Palau
|
||||
PS=Palestine
|
||||
PA=Panama
|
||||
PG=Papua New Guinea
|
||||
PY=Paraguay
|
||||
PE=Peru
|
||||
PH=Philippines
|
||||
PN=Pitcairn
|
||||
PL=Poland
|
||||
PT=Portugal
|
||||
PR=Puerto Rico
|
||||
QA=Qatar
|
||||
RE=Réunion
|
||||
RO=Romania
|
||||
RU=Russia
|
||||
RW=Rwanda
|
||||
BL=Saint Barthélemy
|
||||
SH=Saint Helena
|
||||
KN=Saint Kitts and Nevis
|
||||
LC=Saint Lucia
|
||||
MF=Saint Martin
|
||||
PM=Saint Pierre and Miquelon
|
||||
VC=Saint Vincent and the Grenadines
|
||||
WS=Samoa
|
||||
SM=San Marino
|
||||
ST=Sao Tome and Principe
|
||||
SA=Saudi Arabia
|
||||
SN=Senegal
|
||||
RS=Serbia
|
||||
SC=Seychelles
|
||||
SL=Sierra Leone
|
||||
SG=Singapore
|
||||
SX=Sint Maarten
|
||||
SK=Slovakia
|
||||
SI=Slovenia
|
||||
SB=Solomon Islands
|
||||
SO=Somalia
|
||||
ZA=South Africa
|
||||
GS=South Georgia and the South Sandwich Islands
|
||||
SS=South Sudan
|
||||
ES=Spain
|
||||
LK=Sri Lanka
|
||||
SD=Sudan
|
||||
SR=Suriname
|
||||
SJ=Svalbard and Jan Mayen
|
||||
SE=Sweden
|
||||
CH=Switzerland
|
||||
SY=Syria
|
||||
TW=Taiwan
|
||||
TJ=Tajikistan
|
||||
TZ=Tanzania
|
||||
TH=Thailand
|
||||
TL=Timor-Leste
|
||||
TG=Togo
|
||||
TK=Tokelau
|
||||
TO=Tonga
|
||||
TT=Trinidad and Tobago
|
||||
TN=Tunisia
|
||||
TR=Türkiye
|
||||
TM=Turkmenistan
|
||||
TC=Turks and Caicos Islands
|
||||
TV=Tuvalu
|
||||
UG=Uganda
|
||||
UA=Ukraine
|
||||
AE=United Arab Emirates
|
||||
GB=United Kingdom
|
||||
US=United States
|
||||
UM=U.S. Minor Outlying Islands
|
||||
UY=Uruguay
|
||||
UZ=Uzbekistan
|
||||
VU=Vanuatu
|
||||
VE=Venezuela
|
||||
VN=Vietnam
|
||||
VG=Virgin Islands (British)
|
||||
VI=Virgin Islands (U.S.)
|
||||
WF=Wallis and Futuna
|
||||
EH=Western Sahara
|
||||
YE=Yemen
|
||||
ZM=Zambia
|
||||
ZW=Zimbabwe
|
||||
8
scripts/monitoring/tor_inbound_connects.sh
Executable file
8
scripts/monitoring/tor_inbound_connects.sh
Executable file
|
|
@ -0,0 +1,8 @@
|
|||
#!/bin/sh
|
||||
for ((;;))
|
||||
do
|
||||
date &&
|
||||
echo -n "Tor IPv4 inbound connects: "; ss -s -4 | grep 192.168.100.95:https | wc -l &&
|
||||
echo -n "Tor IPv6 inbound connects: "; ss -s -6 | grep -E '::1]:https' | wc -l &&
|
||||
sleep 3600
|
||||
done
|
||||
2
scripts/monitoring/tor_show_relays--koopa+firecuda.sh
Executable file
2
scripts/monitoring/tor_show_relays--koopa+firecuda.sh
Executable file
|
|
@ -0,0 +1,2 @@
|
|||
#!/bin/bash
|
||||
for ((;;)); do date && time ./tor_show_relays.sh -5000 | grep '|' | cat -n | grep -Ei 'koopa|firecuda' && sleep 86400; done
|
||||
108
scripts/monitoring/tor_show_relays.sh
Executable file
108
scripts/monitoring/tor_show_relays.sh
Executable file
|
|
@ -0,0 +1,108 @@
|
|||
#!/bin/bash
|
||||
|
||||
CACHE_DIR="cache"
|
||||
COUNTRY_FILE="countries.txt"
|
||||
DEFAULT_TOP=100
|
||||
TOPN=$DEFAULT_TOP
|
||||
|
||||
mkdir -p "$CACHE_DIR"
|
||||
|
||||
# Parse -N flag
|
||||
if [[ "$1" =~ ^-([0-9]+)$ ]]; then
|
||||
TOPN="${BASH_REMATCH[1]}"
|
||||
fi
|
||||
|
||||
# ===========================
|
||||
# LOAD COUNTRY NAMES
|
||||
# ===========================
|
||||
|
||||
declare -A COUNTRY_NAME
|
||||
while IFS='=' read -r ISO NAME; do
|
||||
[[ -z "$ISO" ]] && continue
|
||||
COUNTRY_NAME["$ISO"]="$NAME"
|
||||
done < "$COUNTRY_FILE"
|
||||
|
||||
# ===========================
|
||||
# SMART FETCH (ETag-based)
|
||||
# ===========================
|
||||
|
||||
fetch_if_new() {
|
||||
local url="$1"
|
||||
local outfile="$2"
|
||||
local etagfile="${outfile}.etag"
|
||||
|
||||
echo "→ Checking $outfile"
|
||||
curl -s \
|
||||
--etag-save "$etagfile" \
|
||||
--etag-compare "$etagfile" \
|
||||
-o "$outfile" \
|
||||
"$url"
|
||||
|
||||
echo " Size: $(du -h "$outfile" | cut -f1)"
|
||||
}
|
||||
|
||||
DETAILS_JSON="$CACHE_DIR/details.json"
|
||||
BANDWIDTH_JSON="$CACHE_DIR/bandwidth.json"
|
||||
MERGED="$CACHE_DIR/merged.txt"
|
||||
|
||||
echo "=== STEP 1: Downloading (if new) ==="
|
||||
fetch_if_new \
|
||||
"https://onionoo.torproject.org/details?type=relay&fields=fingerprint,country,nickname" \
|
||||
"$DETAILS_JSON"
|
||||
|
||||
fetch_if_new \
|
||||
"https://onionoo.torproject.org/bandwidth?type=relay&fields=fingerprint,write_history" \
|
||||
"$BANDWIDTH_JSON"
|
||||
|
||||
# ===========================
|
||||
# STEP 2: MERGE EVERYTHING IN ONE jq PASS
|
||||
# ===========================
|
||||
|
||||
echo
|
||||
echo "=== STEP 2: Merging in jq (single pass) ==="
|
||||
|
||||
jq -s -r '
|
||||
# Build index of details by fingerprint
|
||||
(.[0].relays
|
||||
| map({
|
||||
fp: .fingerprint,
|
||||
country: (.country // "??"),
|
||||
nickname: (.nickname // "UnknownRelay")
|
||||
})
|
||||
| INDEX(.fp)
|
||||
) as $d
|
||||
|
||||
# Iterate over bandwidth relays
|
||||
| .[1].relays[]
|
||||
| .fingerprint as $fp
|
||||
| ($d[$fp].country) as $cc
|
||||
| ($d[$fp].nickname) as $nick
|
||||
| (.write_history["1_month"].factor // 0) as $bw
|
||||
|
||||
# Output: bw fp cc nickname
|
||||
| "\($bw) \($fp) \($cc) \($nick)"
|
||||
' "$DETAILS_JSON" "$BANDWIDTH_JSON" > "$MERGED"
|
||||
|
||||
echo " Merged lines: $(wc -l < "$MERGED")"
|
||||
|
||||
# ===========================
|
||||
# STEP 3: SORT + PRINT
|
||||
# ===========================
|
||||
|
||||
echo
|
||||
echo "=== STEP 3: Sorting and printing ==="
|
||||
echo
|
||||
echo "=== Top $TOPN Tor Relays (by 1-month write factor) ==="
|
||||
echo
|
||||
|
||||
sort -nr "$MERGED" | head -n "$TOPN" | while read -r BW FP CC NICK; do
|
||||
CC_UP=$(echo "$CC" | tr '[:lower:]' '[:upper:]')
|
||||
FULL="${COUNTRY_NAME[$CC_UP]}"
|
||||
[[ -z "$FULL" ]] && FULL="$NICK"
|
||||
|
||||
printf "%-40s | %12.2f | %-20s | %2s (%s)\n" "$FP" "$BW" "$NICK" "$CC_UP" "$FULL"
|
||||
|
||||
done
|
||||
|
||||
echo
|
||||
echo "Done."
|
||||
83
scripts/monitoring/tor_stats_per_country.sh
Executable file
83
scripts/monitoring/tor_stats_per_country.sh
Executable file
|
|
@ -0,0 +1,83 @@
|
|||
#!/bin/bash
|
||||
|
||||
PORT=8080
|
||||
DB="/usr/share/GeoIP/GeoLite2-Country.mmdb"
|
||||
LOGFILE="/dev/null"
|
||||
COUNTRY_FILE="countries.txt"
|
||||
|
||||
declare -A COUNTRY_COUNT
|
||||
declare -A SEEN
|
||||
declare -A COUNTRY_NAME
|
||||
|
||||
# --- Parse -N flag (e.g. -10 means show top 10) ---
|
||||
TOPN=0
|
||||
if [[ "$1" =~ ^-([0-9]+)$ ]]; then
|
||||
TOPN="${BASH_REMATCH[1]}"
|
||||
fi
|
||||
|
||||
# --- Load external country list ---
|
||||
while IFS='=' read -r ISO NAME; do
|
||||
[[ -z "$ISO" ]] && continue
|
||||
COUNTRY_NAME["$ISO"]="$NAME"
|
||||
done < "$COUNTRY_FILE"
|
||||
|
||||
echo "Monitoring port $PORT..."
|
||||
echo "Updating table every 5 seconds."
|
||||
[[ $TOPN -gt 0 ]] && echo "Showing only Top $TOPN countries."
|
||||
|
||||
LAST_REFRESH=0
|
||||
|
||||
while true; do
|
||||
# FAST LOOP: collect new connections
|
||||
IPS=$(ss -tn sport = :$PORT | awk 'NR>1 {print $5}' | cut -d: -f1)
|
||||
|
||||
for IP in $IPS; do
|
||||
[[ "$IP" == "127.0.0.1" ]] && continue
|
||||
|
||||
if [[ -z "${SEEN[$IP]}" ]]; then
|
||||
SEEN[$IP]=1
|
||||
|
||||
RAW=$(mmdblookup --file "$DB" --ip "$IP" country iso_code 2>/dev/null)
|
||||
ISO=$(echo "$RAW" | grep -oE '[A-Z]{2}')
|
||||
[[ -z "$ISO" ]] && ISO="UNKNOWN"
|
||||
|
||||
COUNTRY_COUNT["$ISO"]=$(( COUNTRY_COUNT["$ISO"] + 1 ))
|
||||
|
||||
NAME="${COUNTRY_NAME[$ISO]}"
|
||||
[[ -z "$NAME" ]] && NAME="Unknown Country"
|
||||
|
||||
echo "$(date '+%F %T') - $IP - $ISO ($NAME)" >> "$LOGFILE"
|
||||
fi
|
||||
done
|
||||
|
||||
# SLOW LOOP: refresh display every 5 seconds
|
||||
NOW=$(date +%s)
|
||||
if (( NOW - LAST_REFRESH >= 5 )); then
|
||||
LAST_REFRESH=$NOW
|
||||
|
||||
clear
|
||||
echo "=== Live GeoIP Stats (Port $PORT) ==="
|
||||
echo "(Updated: $(date '+%H:%M:%S'))"
|
||||
echo
|
||||
|
||||
# Sort by count (descending)
|
||||
SORTED=$(for ISO in "${!COUNTRY_COUNT[@]}"; do
|
||||
echo "${COUNTRY_COUNT[$ISO]} $ISO"
|
||||
done | sort -rn)
|
||||
|
||||
COUNT=0
|
||||
while read -r LINE; do
|
||||
NUM=$(echo "$LINE" | awk '{print $1}')
|
||||
ISO=$(echo "$LINE" | awk '{print $2}')
|
||||
NAME="${COUNTRY_NAME[$ISO]}"
|
||||
[[ -z "$NAME" ]] && NAME="Unknown Country"
|
||||
|
||||
echo "$ISO ($NAME): $NUM"
|
||||
|
||||
((COUNT++))
|
||||
[[ $TOPN -gt 0 && $COUNT -ge $TOPN ]] && break
|
||||
done <<< "$SORTED"
|
||||
fi
|
||||
|
||||
sleep 0.1
|
||||
done
|
||||
Loading…
Add table
Add a link
Reference in a new issue