다른 줄에 이와 같은 항목이있는 파일이 있습니다.
Feb 16 17:30:18 ns1 dovecot: pop3-login: Disconnected (auth failed, 1 attempts in 17 secs): user=<[email protected]>, method=PLAIN, rip=200.250.9.210, lip=10.10.10.10, session=<Sed519rVnADI+gnS>
이와 같은 한 줄이 발견 될 때마다 립 부분에 연결된 IP를 추출하고 싶지만 3 회 이상 표시되는 IP를 추출하고 싶습니다.
나는 이것을하기 위해 grep을 사용하려고합니다.
이것은 내가 가진 grep입니다
more /var/log/maillog-20130217 | grep "auth failed" | grep -o '(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4
][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)'
이 grep은 일치하는 행에있는 모든 IP를 표시합니다.
해당 IP와 일치하는 행이 3 개 이상이고 고유 한 IP 만있는 경우 IP 만 표시하도록이 grep을 제한하는 방법은 무엇입니까?
나는 이것을 의미한다. 내 로그에 다음이 있다고 가정합니다.
Feb 16 17:30:18 ns1 dovecot: pop3-login: Disconnected (auth failed, 1 attempts in 17 secs): user=<[email protected]>, method=PLAIN, rip=200.250.9.210, lip=10.10.10.10, session=<Sed519rVnADI+gnS>
Feb 16 17:30:18 ns1 dovecot: pop3-login: Disconnected (auth failed, 1 attempts in 17 secs): user=<[email protected]>, method=PLAIN, rip=200.250.9.210, lip=10.10.10.10, session=<Sed519rVnADI+gnS>
Feb 16 17:30:18 ns1 dovecot: pop3-login: Disconnected (auth failed, 1 attempts in 17 secs): user=<[email protected]>, method=PLAIN, rip=20.20.20.20, lip=10.10.10.10, session=<Sed519rVnADI+gnS>
Feb 16 17:30:18 ns1 dovecot: pop3-login: Disconnected (auth failed, 1 attempts in 17 secs): user=<[email protected]>, method=PLAIN, rip=200.250.9.210, lip=10.10.10.10, session=<Sed519rVnADI+gnS>
나는 grep을 사용하고 200.250.9.210을 얻고 싶습니다.이 IP에 3 줄이 있지만 한 번만 나타나는 20.20.20.20이 아니기 때문입니다.
내 grep을 실행할 때 내가 가진 것은 이것이다
200.250.9.210
200.250.9.210
20.20.20.20
200.250.9.210
즉, 일치하는 행에있는 모든 IP를 나열합니다.
감사.
sed < mail.log -n 's/.*auth failed.*rip=\([^,]*\).*/\1/p' |
sort |
uniq -c |
awk '$1 >= 3' |
sort -rn
발생 횟수별로 정렬 된 발생 횟수와 일치하는 IP 주소를 제공합니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다