notgood
V2EX  ›  问与答

正则表达式难题 求指点 谢谢

  •  1
     
  •   notgood · Mar 21, 2019 · 1426 views
    This topic created in 2612 days ago, the information mentioned may be changed or developed.
    求 V 友帮忙看看指点一下 谢谢!
    目的是想用 fail2ban 屏蔽来探测的 ip
    log 如下 :

    Aug 15 08:59:07 <hostname> ss-server[1382]: 2018-08-15 08:59:07 ERROR: failed to handshake with <HOST>: authentication error

    正规表达式如下:
    failregex = ^\w+\s+\d+ \d+:\d+:\d+\s+%(__prefix_line)sERROR:\s+failed to handshake with <HOST>: authentication error$

    我测试却没法匹配, 不知道问题出在哪?

    fail2ban-regex '2019-03-21 02:50:41 ERROR: failed to handshake with 95.179.169.185: authentication error' '^\w+\s+\d+ \d+:\d+:\d+\s+%(__prefix_line)sERROR:\s+failed to handshake with <HOST>: authentication error$'

    Running tests
    =============

    Use failregex line : ^\w+\s+\d+ \d+:\d+:\d+\s+%(__prefix_line)sERROR:\s...
    Use single line : 2019-03-21 02:50:41 ERROR: failed to handshake wit...


    Results
    =======

    Failregex: 0 total

    Ignoreregex: 0 total

    Date template hits:
    |- [# of hits] date format
    | [1] Year(?P<_sep>[-/.])Month(?P=_sep)Day 24hour:Minute:Second(?:,Microseconds)?
    `-

    Lines: 1 lines, 0 ignored, 0 matched, 1 missed
    [processed in 0.00 sec]

    |- Missed line(s):
    | 2019-03-21 02:50:41 ERROR: failed to handshake with 95.179.169.185: authentication error
    `-
    Supplement 1  ·  Mar 21, 2019
    测试了这个命令也不行

    fail2ban-regex 'Aug 15 08:59:07 <hostname> ss-server[1382]: 2018-08-15 08:59:07 ERROR: failed to handshake with <HOST>: authentication error' '^\w+\s+\d+ \d+:\d+:\d+\s+%(__prefix_line)sERROR:\s+failed to handshake with <HOST>: authentication error$'
    2 replies    2019-03-22 10:07:44 +08:00
    jcsmallming
        1
    jcsmallming  
       Mar 22, 2019
    第二个语句把 '%(__prefix_line)s' 换成 '.*' 倒是能匹配,不太清楚你的 '%(__prefix_line)s' 会替换成什么内容。
    第一个语句看起来应该就是不能匹配的,毕竟你用的是 '+' ,你用 '2019-03-21...' 去匹配,开头的 '^\w+' 要求的至少出现一个字符就已经不能满足了。
    jcsmallming
        2
    jcsmallming  
       Mar 22, 2019
    @jcsmallming 啊,记错了,\w 也能匹配数字来着,第一个语句的问题应该是没有正确匹配到日期的 '-' 符号,不好意思
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1523 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 16:47 · PVG 00:47 · LAX 09:47 · JFK 12:47
    ♥ Do have faith in what you're doing.