-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTarpitAnConv
88 lines (78 loc) · 2.77 KB
/
TarpitAnConv
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import java.io.File
import java.io.FileWriter
import java.io.IOException
import java.io.InputStream
import java.time.LocalDateTime
val Liste1 = mutableListOf<String>()
val Liste2 = mutableListOf<String>()
val Listeconfig = mutableListOf<String>()
val path = System.getProperty("user.dir")
var fileName = "tarpit.log"
var fileName2 = "log.txt"
var fileNameConfig = path + File.separator + "config.txt"
var zaehler: Long = 0
var message3 = " Reading Log-File."
var message4 = " Conversion."
var message5 = " Writing Log-File."
var message6 = " Process finished. \r"
var datumanfang = ""
var datumende = ""
var teilweise = ""
fun main(args: Array<String>) {
println(" ")
val fileExists = File(fileNameConfig).exists()
if (fileExists) {
val inputStream11: InputStream = File(fileNameConfig).inputStream()
inputStream11.bufferedReader().forEachLine { Listeconfig.add(it) }
datumanfang = Listeconfig.elementAt(0).toString()
datumende = Listeconfig.elementAt(1).toString()
teilweise = "1"
}
println(message3)
val inputStream: InputStream = File(path + File.separator + fileName).inputStream()
inputStream.bufferedReader().forEachLine { Liste1.add(it) }
println(message4)
Liste1.forEach { datenaufbereitung(it) }
print(message5)
println(" ")
schreiben()
println(" ")
print(message6)
}
fun datenaufbereitung(zeile: String) {
if (zeile.contains("connected") ) {
val wert1: String = zeile.replace(" INFO TarpitServer: Client ('", ",")
val wert2: String = wert1.replace("', ", ",")
val wert3: String = wert2.replace(") ", ",")
if (teilweise == "1") {
val pos1 = wert3.indexOf(",", 0)
val wert4: String = wert3.substring(0, pos1)
val localDateTime = LocalDateTime.parse(wert4.replace(" ","T"))
val localDateTime2 = LocalDateTime.parse(datumanfang.replace(" ","T"))
val localDateTime3 = LocalDateTime.parse(datumende.replace(" ","T"))
if (localDateTime >= localDateTime2 && localDateTime <= localDateTime3 ) {
Liste2.add(wert3)
zaehler = zaehler + 1
}
} else {
Liste2.add(wert3)
zaehler = zaehler + 1
}
}
}
fun schreiben() {
try {
val fw = FileWriter(path + File.separator + fileName2, true)
var zaehler2: Long = 0
Liste2.forEach { (it)
zaehler2 = zaehler2 + 1
val text = it + System.getProperty("line.separator")
fw.write(text)
var percentage = (zaehler2.toDouble() / zaehler.toDouble()) * 100
var prozent: Int = percentage.toInt()
print( " " + prozent.toString() + "% \r")
}
fw.close()
} catch (e: IOException) {
}
}