How can I find out how many times an ip address has been logged?
What I think is this
192.168.1.254
192.168.1.254
192.168.1.254
192.168.1.254
192.168.1.254
- 10.40.89.79
To this
- 192.168.1.254 (5)
- 10.40.89.79 (1)
syslog_2019-05-15.txt looks like this
DROP IN=eth0 OUT= MAC=38:2c:4a:cb:e2:40:10:e8:78:aa:89:ba:08:00 SRC=92.53.90.242 DST=90.149.222.18 LEN=40 TOS=0x00 PREC=0x00 TTL=243 ID=37773 PROTO=TCP SPT=59155 DPT=1027 SEQ=1687374236 ACK=0 WINDOW=1024 RES=0x00 SYN URGP=0
192.168.1.1 May 14 00:01:44 kern warning kernel DROP IN=eth0 OUT= MAC=38:2c:4a:cb:e2:40:10:e8:78:aa:89:ba:08:00 SRC=185.216.140.6 DST=90.149.222.18 LEN=40 TOS=0x00 PREC=0x00 TTL=248 ID=54321 PROTO=TCP SPT=5
Code:
var fs = require('fs');
fs.readFile('C:/Users/sondr/Desktop/koder/Ip_søk_syslog/syslog_2019-05-15.txt', 'utf8', function(err, data) {
if (err) throw err; {
//count
var count = 0;
//ReEX
const reg = /\bSRC=([\.0-9]+)\b/g;
while ((m = reg.exec(data))) {
console.log("SRC= " + m[1])
console.log(++count);
}
// DEBUG:
//console.log(data);
}
});