惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

L
LangChain Blog
Scott Helme
Scott Helme
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Stack Overflow Blog
Stack Overflow Blog
Forbes - Security
Forbes - Security
T
The Blog of Author Tim Ferriss
Y
Y Combinator Blog
S
Schneier on Security
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Cisco Talos Blog
Cisco Talos Blog
N
News | PayPal Newsroom
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Project Zero
Project Zero
Cyberwarzone
Cyberwarzone
Vercel News
Vercel News
M
MIT News - Artificial intelligence
云风的 BLOG
云风的 BLOG
Google Online Security Blog
Google Online Security Blog
Simon Willison's Weblog
Simon Willison's Weblog
MongoDB | Blog
MongoDB | Blog
Martin Fowler
Martin Fowler
T
Tenable Blog
I
InfoQ
W
WeLiveSecurity
Google DeepMind News
Google DeepMind News
G
Google Developers Blog
D
DataBreaches.Net
博客园 - Franky
Know Your Adversary
Know Your Adversary
Spread Privacy
Spread Privacy
S
Security @ Cisco Blogs
Hacker News: Ask HN
Hacker News: Ask HN
J
Java Code Geeks
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
F
Full Disclosure
C
Cisco Blogs
Google DeepMind News
Google DeepMind News
P
Proofpoint News Feed
C
CXSECURITY Database RSS Feed - CXSecurity.com
The Cloudflare Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
I
Intezer
The GitHub Blog
The GitHub Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
F
Fortinet All Blogs
Jina AI
Jina AI
V
Visual Studio Blog
L
LINUX DO - 热门话题
WordPress大学
WordPress大学
aimingoo的专栏
aimingoo的专栏

博客园 - sunny_2016

核聚:雷·达里奥的达成目标5步法 英语发单规则一 英语学习三 英语学习笔记二 英语学习笔记一 modbus协议 OPC UA协议学习笔记 限制ssh非法登录 linux添加hosts.deny文件 jmeter的tcp请求示例发送16进制报文 pymodbus模拟modbus slave从站(二) 使用python的pymodbus实现modbus slave 模拟从站一 secure crt使用ssh密钥登录提示未知文件格式 专业的通讯调试工具或者平台有哪些 centos7.9上面卸载中文语言包和中文字体重新安装 linux centos7.9 中文乱码 linux pkill命令的坑 Windows 11 主机上建立反向隧道,实现服务端连接内网客户端主机 互联网上的高危IP,一直在尝试sshd破解 通过/etc/hosts.deny限制一个网段的 SSH 登录尝试 多系统集成分析——ERP与OA、PLM、MES、CRM、WMS、SRM、HR ERP也有库存管理、生产管理、流程审批,为什么还要上WMS、MES和OA? gitlab流水线执行发布提示: No such file or directory gitlab-runner注册完提示:New runner. Has not connected yet(新的Runner,尚未连接) 电池片组件生产工艺流程
linux查询近8小时ssh登录失败的ip转换为hosts.deny格式打印
sunny_2016 · 2025-12-11 · via 博客园 - sunny_2016
# 核心命令(兼容大部分系统)
grep -E "Failed password|Invalid user" /var/log/secure \
| awk -v start_time="$(date -d '8 hours ago' +%b' '%d' '%H:%M:%S)" '
    BEGIN {
        # 解析起始时间为时间戳(处理月份缩写+日期+时间格式)
        split(start_time, t, /[: ]/);
        mon_map["Jan"]=1; mon_map["Feb"]=2; mon_map["Mar"]=3; mon_map["Apr"]=4;
        mon_map["May"]=5; mon_map["Jun"]=6; mon_map["Jul"]=7; mon_map["Aug"]=8;
        mon_map["Sep"]=9; mon_map["Oct"]=10; mon_map["Nov"]=11; mon_map["Dec"]=12;
        start_ts = mktime(strftime("%Y") " " mon_map[t[1]] " " t[2] " " t[3] " " t[4] " " t[5]);
    }
    {
        # 解析日志行的时间戳
        log_mon=$1; log_day=$2; log_time=$3;
        log_ts = mktime(strftime("%Y") " " mon_map[log_mon] " " log_day " " substr(log_time,1,2) " " substr(log_time,4,2) " " substr(log_time,7,2));
        # 筛选近8小时的日志行
        if (log_ts >= start_ts) {
            # 提取IP地址(适配不同日志格式)
            for (i=1; i<=NF; i++) {
                if ($i ~ /^([0-9]{1,3}\.){3}[0-9]{1,3}$/) {
                    ip=$i; break;
                }
            }
            if (ip != "") print ip;
        }
    }
' | sort -u | awk '{print "sshd:" $0}'