FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
OnJava8-Examples/strings/ThreatAnalyzer.java at master · CSapprenticeWT/OnJava8-Examples · GitHub
CSapprenticeWT
OnJava8-Examples
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
OnJava8-Examples
/
strings
/
ThreatAnalyzer.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
36 lines (35 loc) · 1.14 KB
Breadcrumbs
OnJava8-Examples
/
strings
/
ThreatAnalyzer.java
Copy path
File metadata and controls
36 lines (35 loc) · 1.14 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// strings/ThreatAnalyzer.java
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
import
java
.
util
.
regex
.*;
import
java
.
util
.*;
public
class
ThreatAnalyzer
{
static
String
threatData
=
"58.27.82.161@08/10/2015
\n
"
+
"204.45.234.40@08/11/2015
\n
"
+
"58.27.82.161@08/11/2015
\n
"
+
"58.27.82.161@08/12/2015
\n
"
+
"58.27.82.161@08/12/2015
\n
"
+
"[Next log section with different data format]"
;
public
static
void
main
(
String
[]
args
) {
Scanner
scanner
=
new
Scanner
(
threatData
);
String
pattern
=
"(
\\
d+[.]
\\
d+[.]
\\
d+[.]
\\
d+)@"
+
"(
\\
d{2}/
\\
d{2}/
\\
d{4})"
;
while
(
scanner
.
hasNext
(
pattern
)) {
scanner
.
next
(
pattern
);
MatchResult
match
=
scanner
.
match
();
String
ip
=
match
.
group
(
1
);
String
date
=
match
.
group
(
2
);
System
.
out
.
format
(
"Threat on %s from %s%n"
,
date
,
ip
);
}
}
}
/* Output:
Threat on 08/10/2015 from 58.27.82.161
Threat on 08/11/2015 from 204.45.234.40
Threat on 08/11/2015 from 58.27.82.161
Threat on 08/12/2015 from 58.27.82.161
Threat on 08/12/2015 from 58.27.82.161
*/
Back
|
FazBrowse Home
|
New Git URL