V
V
Vladimir Yurchenkov2022-03-23 22:16:24
C++ / C#
Vladimir Yurchenkov, 2022-03-23 22:16:24

How are logs depersonalized?

In general (in my head) the task is to depersonalize a large log from ip addresses, hosts, logins, etc.

1) IP search: since there is no specific base and a universal search is needed, I decided to use a regular expression by type:

Regex ip = new Regex(@"\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b");


Со своей задачей справляется, есть маленький вопрос, как заменить в строке только найденный IP?

2) Хосты и логины нахожу по первым символам, все успешно. Но вопрос такой же почти, через Replace без труда могу заменить, но как это сделать к примеру с заменой на +4 символа? Или лучше до первого найденного пробела найденного значения?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
Владимир Юрченков, 2022-03-24
@EPIDEMIASH

I answer my own question.
Masks that I use:
1) To search for IP Regex ip = new Regex(@"\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{ 1,3}\b");
2) To search for hosts (of my kind) Regex host = new Regex(@"[a-zA-Z0-9]{3}-(w*\S+)");
3) To search for logins of 2 types @"(\w*)login(\w*\S+\s)" and @"l[0-9]{3}(\w*\S+\s)
" more than enough, since I only use ip \ hosts and logins in my logs.
You can immediately replace in a cycle

foreach (Match mat in matches)
{
line.Replace(mat.Value, "Конф.информация")
}

M
Maxim K, 2022-03-24
@mkvmaks

Notepad ++ in it you can do a lot at once

V
Vitaly Karasik, 2022-03-24
@vitaly_il1

I would look for ready-made utilities instead of writing regex myself.
For a couple of minutes, I did not find something specific, but I'm sure there is.
https://aircloak.com/top-5-free-data-anonymization...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question