分析网络请求
- 获取实时请求的网址
sudo tcpdump -i eth0 -s 0 -l -A -w - | strings | grep -Ei --line-buffered "GET [^ ]+|POST [^ ]+|Host: " | awk ' /GET|POST/ { # 核心:提取纯GET/POST和path,清理前缀所有无关字符 match($0, /(GET|POST) ([^ ]+)/, arr); # 只匹配GET/POST+路径 method = arr[1]; # 纯GET/POST path = arr[2]; # 纯路径 if (method == "") { method = $1; path = $2; } # 兜底兼容 } /Host: / { if (method != "") { host = $2 gsub(/\r/, "", host) # 输出前再过滤method,确保无杂字符 method_clean = method ~ /^(GET|POST)$/ ? method : substr(method, match(method, /GET|POST/)) print method_clean " http://" host path method = ""; path = ""; # 重置避免重复 } } ' - 使用 tshark 捕获完整的访问链接,运行 30 秒后自动停止
sudo timeout -k 2 30s tshark -i eth0 -T fields -e http.request.method -e http.host -e http.request.uri -Y "http.request" - 使用 tshark 仅获取不重复的域名请求,将输出结果进行进一步处理,通过 awk 和 sort 等工具实现去重,运行 30 秒后自动停止
sudo timeout -k 2 30s tshark -i eth0 -T fields -e http.request.method -e http.host -e http.request.uri -Y "http.request" | awk -F ',' '{printf "%s %s%s\n", $1, $2, $3}' | sudo sort -u > unique_domains.txt - 实时监控nginx访问日志
tail -f /www/wwwlogs/*.log | awk '{print $6, "https://" $2 $7}'