Monday, April 29, 2024
8
rated 0 times [  8] [ 0]  / answers: 1 / hits: 1318  / 2 Years ago, mon, july 25, 2022, 4:01:34

There is log-file /var/log/syslog
with the output of ip-addresses
like e.g. SRC=10.158.0.1.



I want to scan from this file every printed address in SRC= ... and then to make query with whois (SRC= ...).



This query should be monitored.



Mine attempt is wrong and looks like this in a bash-script:



#/bin/bash

while [ 1 ]
do
grep ‘SRC=ip-address’ /var/log/syslog >> /home/$user/topsecret001/pitbull001.txt;
whois ‘SRC=ip-address’ >> /home/$user/topsecret001/pitbull002.txt;
done


Can somebody help with a trick ? How should I define ip-address and how can
I use command whois with this ip-address ?



The output of /var/log/syslog looks like this snippet here :



http://paste.ubuntu.com/5859332/



The output of /var/log/syslog looks like this - when there is a little alert (like today) :



http://paste.ubuntu.com/5862958/



Idea would be too - to perform a whois-query only if there is "invalid state" popping up in the line of the scrolling syslog.






Thank you for your contributions. I have learnt something by your codes. Often the solutions are looking easier than thought like here - cause I thought it would be more difficulty. I think with recent contribution of enzotib then this question is solved already now.






see new comment of today (22nd June 2016) referring to 16.04 :



because this bash-script was for times of ipv4 - does then /etc/sysctl.conf needs to be un-commented to enable ipv4 ? - then this script would run ? otherwise there is no whois-output any more like before. Have checked this with uncommenting line 28 and line 33 of /etc/sysctl.conf - then this bash-script in this thread would work, but deliver very few output because provider has enabled firewall (because of no-spy-act ?). This way by this addition of 22nd June 2016 this thread is actualized for 16.04


More From » command-line

 Answers
4

Yet another solution:



awk '{ 
for (i = 1; i <= NF; i++)
if ($i ~ /^SRC=/)
print substr($i, 5)
}' /var/log/syslog |
sort -u |
while read ip; do
printf ' === %s ===
' "$ip"
whois "$ip"
done


If you only want to select lines of syslog containing the string INVALID STATE, then the above code can be modified as follows



awk '/INVALID STATE/ { 
for (i = 1; i <= NF; i++)
if ($i ~ /^SRC=/)
print substr($i, 5)
}' /var/log/syslog |
sort -u |
while read ip; do
printf ' === %s ===
' "$ip"
whois "$ip"
done

[#30771] Tuesday, July 26, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
tresein

Total Points: 197
Total Questions: 113
Total Answers: 112

Location: Hungary
Member since Wed, Nov 9, 2022
2 Years ago
tresein questions
Tue, Jun 28, 22, 17:57, 2 Years ago
Sun, Apr 3, 22, 07:11, 2 Years ago
Thu, Feb 3, 22, 18:03, 2 Years ago
Sat, May 13, 23, 13:00, 1 Year ago
;