send-suspicips.sh
· 1.9 KiB · Bash
Raw
#!/bin/sh
#
# Author: Dominic Reich <quick.hat4396@qtztsjosmprqmgtunjyf.com>
suspicfile=~/suspic
tmpfile=/tmp/ips
clean_up() {
echo -n "Removing tmp file..."
rm -f $tmpfile
rm -f $suspicfile
if [ "$?" -eq "0" ]; then
echo " done"
else
echo " *** FAILED ***"
echo "Could not delete tmp file \`$tmpfile\`"
exit 1
fi
}
# inspect url files first by hand
echo -n "Inspecting first..."
ret="$(alacritty -e $EDITOR $suspicfile)"
if [ "$?" -eq "0" ]; then
echo " done"
else
echo " *** FAILED ***"
ecoh "Could not open editor. Aborting..."
clean_up
exit 1
fi
# awk '{ print $1 }' $suspicfile | sort -h | uniq > ips
# Remove false-positives (like requests to the /posts URL which should be valid)
# I used some bad words in some filenames like "admin-panel..."
sed '/posts\//d' $suspicfile | awk '{ print $1 }' | sort -h | uniq > $tmpfile
ips_1=`wc -l $tmpfile | awk '{ print $1 }'`
#ip=`ifconfig | grep inet | egrep -v "inet6|127" | grep 0xffffff00 | awk '{ print $2 }'`
ip=`curl -s ifconfig.me`
echo "My remote ip address is $ip"
sed -i "/$ip/d" $tmpfile
ips_2=`wc -l $tmpfile | awk '{ print $1 }'`
removed_ips=`expr "$ips_1" - "$ips_2"`
echo "Removed $removed_ips ip address(es)"
echo -n "Inspecting ip file..."
ret="$(alacritty -e $EDITOR $tmpfile)"
if [ "$?" -eq "0" ]; then
echo " done"
else
echo " *** FAILED ***"
echo "Could not open editor. Aborting..."
clean_up
exit 1
fi
echo -n "Sending to bor..."
ret="$(scp -q $tmpfile bor:)"
if [ "$?" -eq "0" ]; then
echo " done"
else
echo " *** FAILED ***"
echo "Could not send the new ips to the OpenBSD server. Aborting..."
clean_up
exit 1
fi
echo -n "Sending to celeste..."
ret="$(scp -q $tmpfile celeste:)"
if [ "$?" -eq "0" ]; then
echo " done"
else
echo " *** FAILED ***"
echo "Could not send the new ips to the Archlinux server. Aborting..."
clean_up
exit 1
fi
clean_up
echo "Ok all done."
1 | #!/bin/sh |
2 | # |
3 | # Author: Dominic Reich <quick.hat4396@qtztsjosmprqmgtunjyf.com> |
4 | |
5 | suspicfile=~/suspic |
6 | tmpfile=/tmp/ips |
7 | |
8 | clean_up() { |
9 | echo -n "Removing tmp file..." |
10 | rm -f $tmpfile |
11 | rm -f $suspicfile |
12 | if [ "$?" -eq "0" ]; then |
13 | echo " done" |
14 | else |
15 | echo " *** FAILED ***" |
16 | echo "Could not delete tmp file \`$tmpfile\`" |
17 | exit 1 |
18 | fi |
19 | } |
20 | |
21 | # inspect url files first by hand |
22 | echo -n "Inspecting first..." |
23 | ret="$(alacritty -e $EDITOR $suspicfile)" |
24 | |
25 | if [ "$?" -eq "0" ]; then |
26 | echo " done" |
27 | else |
28 | echo " *** FAILED ***" |
29 | ecoh "Could not open editor. Aborting..." |
30 | clean_up |
31 | exit 1 |
32 | fi |
33 | |
34 | # awk '{ print $1 }' $suspicfile | sort -h | uniq > ips |
35 | |
36 | # Remove false-positives (like requests to the /posts URL which should be valid) |
37 | # I used some bad words in some filenames like "admin-panel..." |
38 | sed '/posts\//d' $suspicfile | awk '{ print $1 }' | sort -h | uniq > $tmpfile |
39 | |
40 | ips_1=`wc -l $tmpfile | awk '{ print $1 }'` |
41 | |
42 | #ip=`ifconfig | grep inet | egrep -v "inet6|127" | grep 0xffffff00 | awk '{ print $2 }'` |
43 | ip=`curl -s ifconfig.me` |
44 | echo "My remote ip address is $ip" |
45 | |
46 | sed -i "/$ip/d" $tmpfile |
47 | ips_2=`wc -l $tmpfile | awk '{ print $1 }'` |
48 | |
49 | removed_ips=`expr "$ips_1" - "$ips_2"` |
50 | |
51 | echo "Removed $removed_ips ip address(es)" |
52 | |
53 | echo -n "Inspecting ip file..." |
54 | ret="$(alacritty -e $EDITOR $tmpfile)" |
55 | |
56 | if [ "$?" -eq "0" ]; then |
57 | echo " done" |
58 | else |
59 | echo " *** FAILED ***" |
60 | echo "Could not open editor. Aborting..." |
61 | clean_up |
62 | exit 1 |
63 | fi |
64 | |
65 | echo -n "Sending to bor..." |
66 | ret="$(scp -q $tmpfile bor:)" |
67 | |
68 | if [ "$?" -eq "0" ]; then |
69 | echo " done" |
70 | else |
71 | echo " *** FAILED ***" |
72 | echo "Could not send the new ips to the OpenBSD server. Aborting..." |
73 | clean_up |
74 | exit 1 |
75 | fi |
76 | |
77 | echo -n "Sending to celeste..." |
78 | ret="$(scp -q $tmpfile celeste:)" |
79 | |
80 | if [ "$?" -eq "0" ]; then |
81 | echo " done" |
82 | else |
83 | echo " *** FAILED ***" |
84 | echo "Could not send the new ips to the Archlinux server. Aborting..." |
85 | clean_up |
86 | exit 1 |
87 | fi |
88 | |
89 | clean_up |
90 | |
91 | echo "Ok all done." |
92 |