说明
^((?:[0-9]{2}[-\/:.]){5}[0-9]{6}).*[{]TCP[}]\s*(((?:[0-9]{1,3}[.]){1,3}[0-9]{1,3}):([0-9]{1,6}))\s*->\s*(((?:[0-9]{1,3}[.]){1,3}[0-9]{1,3}):([0-9]{1,6}))
** 要更好地查看图像,只需右键单击图像并选择在新窗口中查看
此正则表达式将执行以下操作:
- 将时间戳捕获到捕获组 1
- 将源 IP 地址和端口捕获到捕获组 2、3、4
- 将目标 IP 地址和端口捕获到捕获组 5、6、7 中
- 要求 IP 源和目标由
{TCP} 处理,以防消息还包含 IP 地址。
示例
现场演示
https://regex101.com/r/hD4fW8/1
示例文本
03/09-14:10:43.323717 [**] [1:2008015:9] ET MALWARE User-Agent (Win95) [**] [Classification: A Network Trojan was detected] [Priority: 1] {TCP} 172.16.116.194:28692 -> 205.181.112.65:80
示例匹配
MATCH 1
1. [0-21] `03/09-14:10:43.323717`
2. [145-165] `172.16.116.194:28692`
3. [145-159] `172.16.116.194`
4. [160-165] `28692`
5. [169-186] `205.181.112.65:80`
6. [169-183] `205.181.112.65`
7. [184-186] `80`
说明
NODE EXPLANATION
----------------------------------------------------------------------
^ the beginning of the string
----------------------------------------------------------------------
( group and capture to \1:
----------------------------------------------------------------------
(?: group, but do not capture (5 times):
----------------------------------------------------------------------
[0-9]{2} any character of: '0' to '9' (2 times)
----------------------------------------------------------------------
[-\/:.] any character of: '-', '\/', ':', '.'
----------------------------------------------------------------------
){5} end of grouping
----------------------------------------------------------------------
[0-9]{6} any character of: '0' to '9' (6 times)
----------------------------------------------------------------------
) end of \1
----------------------------------------------------------------------
.* any character except \n (0 or more times
(matching the most amount possible))
----------------------------------------------------------------------
[{] any character of: '{'
----------------------------------------------------------------------
TCP 'TCP'
----------------------------------------------------------------------
[}] any character of: '}'
----------------------------------------------------------------------
\s* whitespace (\n, \r, \t, \f, and " ") (0 or
more times (matching the most amount
possible))
----------------------------------------------------------------------
( group and capture to \2:
----------------------------------------------------------------------
( group and capture to \3:
----------------------------------------------------------------------
(?: group, but do not capture (between 1
and 3 times (matching the most amount
possible)):
----------------------------------------------------------------------
[0-9]{1,3} any character of: '0' to '9'
(between 1 and 3 times (matching the
most amount possible))
----------------------------------------------------------------------
[.] any character of: '.'
----------------------------------------------------------------------
){1,3} end of grouping
----------------------------------------------------------------------
[0-9]{1,3} any character of: '0' to '9' (between
1 and 3 times (matching the most
amount possible))
----------------------------------------------------------------------
) end of \3
----------------------------------------------------------------------
: ':'
----------------------------------------------------------------------
( group and capture to \4:
----------------------------------------------------------------------
[0-9]{1,6} any character of: '0' to '9' (between
1 and 6 times (matching the most
amount possible))
----------------------------------------------------------------------
) end of \4
----------------------------------------------------------------------
) end of \2
----------------------------------------------------------------------
\s* whitespace (\n, \r, \t, \f, and " ") (0 or
more times (matching the most amount
possible))
----------------------------------------------------------------------
-> '->'
----------------------------------------------------------------------
\s* whitespace (\n, \r, \t, \f, and " ") (0 or
more times (matching the most amount
possible))
----------------------------------------------------------------------
( group and capture to \5:
----------------------------------------------------------------------
( group and capture to \6:
----------------------------------------------------------------------
(?: group, but do not capture (between 1
and 3 times (matching the most amount
possible)):
----------------------------------------------------------------------
[0-9]{1,3} any character of: '0' to '9'
(between 1 and 3 times (matching the
most amount possible))
----------------------------------------------------------------------
[.] any character of: '.'
----------------------------------------------------------------------
){1,3} end of grouping
----------------------------------------------------------------------
[0-9]{1,3} any character of: '0' to '9' (between
1 and 3 times (matching the most
amount possible))
----------------------------------------------------------------------
) end of \6
----------------------------------------------------------------------
: ':'
----------------------------------------------------------------------
( group and capture to \7:
----------------------------------------------------------------------
[0-9]{1,6} any character of: '0' to '9' (between
1 and 6 times (matching the most
amount possible))
----------------------------------------------------------------------
) end of \7
----------------------------------------------------------------------
) end of \5
----------------------------------------------------------------------