New We are sorting MAX channels into categories and territories. Read the news

🧠 Регулярки на практике: как вытащить IP-адреса из логов



Когда нужно быстро достать все IP-адреса из логов — тебе на помощь приходит grep + регулярные выражения 💪

Пример:

grep -oE '\b([0-9]{1,3}\.){3}[0-9]{1,3}\b' /var/log/nginx/access.log

🔍 Что делает:

-o — выводит только совпадения, без строки целиком
-E — расширенные регулярки
\b([0-9]{1,3}\.){3}[0-9]{1,3}\b — паттерн для IPv4

📌 Пример вывода:

192.168.0.1
10.0.0.55
172.16.100.7


🛡️ Хочешь избавиться от дубликатов?

grep -oE '\b([0-9]{1,3}\.){3}[0-9]{1,3}\b' /var/log/nginx/access.log | sort -u

📁 Подходит для Apache, Nginx, sshd и других логов, где есть IP.

👉 @bash_srv
Views: 1 106
Open in MAX Report an inaccuracy

Report an inaccuracy

Describe what needs fixing. If you have a source, add a link.

You are leaving datool.ru

The link leads to an external website. datool.ru is not responsible for its content — check the address before entering passwords or payment details.

Redirecting in 10 s

Go