Skip to content

Commit 5583b9d

Browse files
committed
add optional cloudflare ip verification
1 parent 6970dac commit 5583b9d

2 files changed

Lines changed: 149 additions & 22 deletions

File tree

README.md

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ A lightweight Bash tool to scan common CDN ports on a list of IPs and domains.
66

77
The **SNI Scanner** is a simple Bash-based tool designed to check common HTTPS/CDN ports on multiple IP addresses or domains. It supports mixed input (IPs and domains), automatically resolves domains to IP addresses, and scans a list of ports commonly used by CDN providers like Cloudflare.
88

9-
The tool provides a clear output indicating which ports are open or closed, supports retries, concurrent scanning, logging, and generates a final categorized summary report.
9+
The tool provides a clear output indicating which ports are open or closed, supports retries, concurrent scanning, logging, optional IP verification through Cloudflare, and generates a final categorized summary report.
1010

1111
## Features
1212

@@ -22,6 +22,10 @@ The tool provides a clear output indicating which ports are open or closed, supp
2222
- Separates successful and failed targets
2323
- Detects unresolved domains
2424
- Filters internal/blocked IPs (10.x.x.x)
25+
- Optional IP Verification:
26+
- Automatically detects your public IP
27+
- Or allows manual IP input
28+
- Verifies the IP seen by Cloudflare using `/cdn-cgi/trace`
2529
- Lightweight & Fast: Requires only bash, nc, and dig
2630

2731
## Getting Started
@@ -32,6 +36,7 @@ The tool provides a clear output indicating which ports are open or closed, supp
3236
- bash
3337
- nc (netcat)
3438
- dig (DNS utilities)
39+
- curl
3540

3641
### Installation
3742

@@ -79,6 +84,18 @@ Custom example:
7984
./sni-scanner.sh -f my-targets.txt -p 80,443,8443 -t 3 -r 2 -l result.log
8085
```
8186

87+
IP verification (auto detect):
88+
89+
```bash
90+
./sni-scanner.sh -ip
91+
```
92+
93+
IP verification (manual IP):
94+
95+
```bash
96+
./sni-scanner.sh -ip 1.2.3.4
97+
```
98+
8299
## CLI Options
83100

84101
| Option | Default | Description | Example |
@@ -88,12 +105,13 @@ Custom example:
88105
| `-t` | `5` | Connection timeout in seconds | `-t 3` |
89106
| `-r` | `3` | Retry count for closed ports | `-r 2` |
90107
| `-l` | `log.txt` | Output log file | `-l result.log` |
108+
| `-ip` | - | Enable IP verification (optional manual IP) | `-ip` or `-ip 1.2.3.4` |
91109
| `-h` | - | Show help menu | `-h` |
92110

93111
## Output Example
94112

95113
```txt
96-
[OK] example.com -> 104.19.229.21 -> 443✔ 2053✔ 2083✖ 2087✖ 2096✖ 8443✔
114+
[OK] example.com -> 104.19.229.21 -> 443✔ 2053✔ 2083✖ 2087✖ 2096✖ 8443✔ IP✔
97115
98116
[FAIL] 8.8.8.8 -> 8.8.8.8 -> 443✖ 2053✖ 2083✖ 2087✖ 2096✖ 8443✖
99117
@@ -107,14 +125,16 @@ Custom example:
107125
At the end of the scan, the tool generates a categorized summary including:
108126

109127
- OK targets
128+
- IP verified targets
110129
- Failed targets
111130
- Resolve failed targets
112131
- Filtered/internal IPs
113132

114133
## Notes
115134

116-
- This tool performs basic TCP port checks only
117-
- It does NOT perform real SNI spoofing or TLS validation
135+
- This tool performs TCP port checks and optional Cloudflare IP verification
136+
- IP verification uses Cloudflare `/cdn-cgi/trace`
137+
- It does NOT perform real TLS fingerprint spoofing
118138
- Results may vary depending on CDN behavior and network restrictions
119139

120140
## Contribution

sni-scanner.sh

Lines changed: 125 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,60 @@ RETRIES=3
88
LOG_FILE="log.txt"
99
CONCURRENCY=20
1010

11+
ENABLE_IP_CHECK=false
12+
MANUAL_IP=""
13+
USER_IP_API="http://chabokan.net/ip/"
14+
1115
usage() {
12-
echo "Usage: $0 [-f file] [-p ports] [-t timeout] [-r retries] [-l log_file]"
13-
echo " -f Input file containing domains/IPs (default: targets.txt)"
14-
echo " -p Comma-separated ports to scan (default: 443,2053,2083,2087,2096,8443)"
15-
echo " -t Timeout in seconds for each connection (default: 5)"
16-
echo " -r Number of retries for closed ports (default: 3)"
17-
echo " -l Output log file (default: log.txt)"
16+
echo "Usage: $0 [-f file] [-p ports] [-t timeout] [-r retries] [-l log_file] [-ip [IP]]"
17+
echo " -f Input file containing domains/IPs"
18+
echo " -p Comma-separated ports"
19+
echo " -t Timeout in seconds"
20+
echo " -r Number of retries"
21+
echo " -l Output log file"
22+
echo " -ip Enable IP verification (optional manual IP)"
1823
exit 1
1924
}
2025

2126
# Parse CLI arguments
22-
while getopts "f:p:t:r:l:h" opt; do
23-
case $opt in
24-
f) INPUT_FILE="$OPTARG" ;;
25-
p) PORTS="$OPTARG" ;;
26-
t) TIMEOUT="$OPTARG" ;;
27-
r) RETRIES="$OPTARG" ;;
28-
l) LOG_FILE="$OPTARG" ;;
29-
h|*) usage ;;
27+
while [[ $# -gt 0 ]]; do
28+
case "$1" in
29+
-f)
30+
INPUT_FILE="$2"
31+
shift 2
32+
;;
33+
-p)
34+
PORTS="$2"
35+
shift 2
36+
;;
37+
-t)
38+
TIMEOUT="$2"
39+
shift 2
40+
;;
41+
-r)
42+
RETRIES="$2"
43+
shift 2
44+
;;
45+
-l)
46+
LOG_FILE="$2"
47+
shift 2
48+
;;
49+
-ip)
50+
ENABLE_IP_CHECK=true
51+
52+
if [[ -n "$2" && ! "$2" =~ ^- ]]; then
53+
MANUAL_IP="$2"
54+
shift 2
55+
else
56+
shift
57+
fi
58+
;;
59+
-h|--help)
60+
usage
61+
;;
62+
*)
63+
usage
64+
;;
3065
esac
3166
done
3267

@@ -40,6 +75,69 @@ IFS=',' read -r -a PORT_ARRAY <<< "$PORTS"
4075
# Initialize/Clear log file
4176
> "$LOG_FILE"
4277

78+
get_user_public_ip() {
79+
local ip=""
80+
81+
for i in {1..3}; do
82+
ip=$(curl -s --connect-timeout 10 --max-time 20 "$USER_IP_API" 2>/dev/null \
83+
| grep -oE '"ip"[[:space:]]*:[[:space:]]*"[^"]+"' \
84+
| cut -d'"' -f4)
85+
86+
if [ -n "$ip" ]; then
87+
echo "$ip"
88+
return
89+
fi
90+
91+
sleep 1
92+
done
93+
}
94+
95+
USER_PUBLIC_IP=""
96+
97+
if [ "$ENABLE_IP_CHECK" = true ]; then
98+
99+
if [ -n "$MANUAL_IP" ]; then
100+
USER_PUBLIC_IP="$MANUAL_IP"
101+
echo "[INFO] Using Manual IP: $USER_PUBLIC_IP" | tee -a "$LOG_FILE"
102+
else
103+
USER_PUBLIC_IP=$(get_user_public_ip)
104+
105+
if [ -n "$USER_PUBLIC_IP" ]; then
106+
echo "[INFO] Auto Detected IP: $USER_PUBLIC_IP" | tee -a "$LOG_FILE"
107+
fi
108+
fi
109+
110+
if [ -z "$USER_PUBLIC_IP" ]; then
111+
echo "[WARNING] Could not detect your public IP" | tee -a "$LOG_FILE"
112+
fi
113+
fi
114+
115+
check_ip() {
116+
local domain=$1
117+
local ip=$2
118+
119+
local detected_ip
120+
121+
detected_ip=$(curl -sk \
122+
--connect-timeout 10 \
123+
--max-time 20 \
124+
--resolve "${domain}:443:${ip}" \
125+
"https://${domain}/cdn-cgi/trace" 2>/dev/null \
126+
| grep '^ip=' \
127+
| cut -d'=' -f2)
128+
129+
if [ -z "$detected_ip" ]; then
130+
echo " IP✖"
131+
return
132+
fi
133+
134+
if [ "$detected_ip" = "$USER_PUBLIC_IP" ]; then
135+
echo " IP✔"
136+
else
137+
echo " IP✖($detected_ip)"
138+
fi
139+
}
140+
43141
process_target() {
44142
local target=$1
45143
local ips=()
@@ -59,7 +157,7 @@ process_target() {
59157
fi
60158

61159
for ip in "${ips[@]}"; do
62-
# Filtering check for IPs starting with 10.
160+
63161
if [[ $ip =~ ^10\. ]]; then
64162
domain_buffer+="[FILTERED] $target -> $ip (Blocked/Internal IP)\n"
65163
continue
@@ -70,6 +168,7 @@ process_target() {
70168

71169
for port in "${PORT_ARRAY[@]}"; do
72170
local port_status="closed"
171+
73172
for ((i=1; i<=RETRIES; i++)); do
74173
if nc -z -w "$TIMEOUT" "$ip" "$port" 2>/dev/null; then
75174
port_status="open"
@@ -86,13 +185,19 @@ process_target() {
86185
done
87186

88187
if [ $open_count -gt 0 ]; then
89-
domain_buffer+="[OK] $result_str\n"
188+
189+
if [ "$ENABLE_IP_CHECK" = true ] && [ -n "$USER_PUBLIC_IP" ]; then
190+
ip_result=$(check_ip "$target" "$ip")
191+
domain_buffer+="[OK] $result_str$ip_result\n"
192+
else
193+
domain_buffer+="[OK] $result_str\n"
194+
fi
195+
90196
else
91197
domain_buffer+="[FAIL] $result_str\n"
92198
fi
93199
done
94200

95-
# Print the entire domain block to keep Multi-IPs together
96201
printf "$domain_buffer" | tee -a "$LOG_FILE"
97202
}
98203

@@ -107,7 +212,9 @@ process_target() {
107212
# Process loop
108213
while IFS= read -r line || [[ -n "$line" ]]; do
109214
[[ -z "$line" || "$line" =~ ^# ]] && continue
215+
110216
target=$(echo "$line" | tr -d '\r' | xargs)
217+
111218
[ -z "$target" ] && continue
112219

113220
process_target "$target" &
@@ -125,7 +232,7 @@ wait
125232
echo "==================================================="
126233
echo " FINAL SUMMARY "
127234
echo "==================================================="
128-
echo "" # Space after title
235+
echo ""
129236

130237
OK_COUNT=$(grep -c "^\[OK\]" "$LOG_FILE" || true)
131238
FAIL_COUNT=$(grep -c "^\[FAIL\]" "$LOG_FILE" || true)

0 commit comments

Comments
 (0)