wget -qO - http://infiltrated.net/blacklisted|awk '!/#|[a-z]/&&/./{print "iptables -A INPUT -s "$1" -j DROP"}'|head -n 2 iptables -A INPUT -s 99.245.29.38 -j DROP iptables -A INPUT -s 97.81.54.226 -j DROP To have them automatically blocked: wget -qO - http://infiltrated.net/blacklisted|awk '!/#|[a-z]/&&/./{print "iptables -A INPUT -s "$1" -j DROP"}'|sh
Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?
You must be signed in to comment.
commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.
Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.
» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10
Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):
Subscribe to the feed for:
more test
99.69.161.123 99.69.161.123 99.69.161.123 99.68.231.37 99.58.203.81 99.4.136.182 99.38.203.228 99.36.16.156 99.31.123.191 99.27.202.67 Let's number them:sed '/./=' test | sed '/./N; s/\n/ /'
1 99.69.161.123 2 99.69.161.123 3 99.69.161.123 4 99.68.231.37 5 99.58.203.81 6 99.4.136.182 7 99.38.203.228 8 99.36.16.156 9 99.31.123.191 10 99.27.202.67 So we see lines 1, 2, 3 are the same... There are a few ways to sort them uniquely. Since I began using awk, here is how to do so with awk:awk '!/#|[a-z]/&&/./{print "iptables -A INPUT -s "$1" -j DROP" | "sort -u"}' test
Notice how I use the sort command inside awk? There is no reason to re-pipe it through to sort: awk by itselfawk '!/#|[a-z]/&&/./{print "iptables -A INPUT -s "$1" -j DROP"}' test
iptables -A INPUT -s 99.69.161.123 -j DROP iptables -A INPUT -s 99.69.161.123 -j DROP iptables -A INPUT -s 99.69.161.123 -j DROP iptables -A INPUT -s 99.68.231.37 -j DROP iptables -A INPUT -s 99.58.203.81 -j DROP iptables -A INPUT -s 99.4.136.182 -j DROP iptables -A INPUT -s 99.38.203.228 -j DROP iptables -A INPUT -s 99.36.16.156 -j DROP iptables -A INPUT -s 99.31.123.191 -j DROP iptables -A INPUT -s 99.27.202.67 -j DROP awk with sort -u (-u is for unique instead of: more filename | sort | uniq)awk '!/#|[a-z]/&&/./{print "iptables -A INPUT -s "$1" -j DROP"}' test | sort -u
iptables -A INPUT -s 99.27.202.67 -j DROP iptables -A INPUT -s 99.31.123.191 -j DROP iptables -A INPUT -s 99.36.16.156 -j DROP iptables -A INPUT -s 99.38.203.228 -j DROP iptables -A INPUT -s 99.4.136.182 -j DROP iptables -A INPUT -s 99.58.203.81 -j DROP iptables -A INPUT -s 99.68.231.37 -j DROP iptables -A INPUT -s 99.69.161.123 -j DROP Why bother going through this when I can just use sort inside of awk. The uglier and bloated way would be something like: awk '!/#|[a-z]/&&/./{print "iptables -A INPUT -s "$1" -j DROP"}' filename | sort | uniq Or even uglier: curl www.infiltrated.net/blacklisted | ruby -ne 'puts $_ unless $_ == @prev; @prev = $_' | awk '{print "iptables -A INPUT -s "$1" -j DROP"}'awk '!/#|[a-z]/&&/./{print "iptables -A INPUT -s "$1" -j DROP" | "sort -u"}'