- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- A really fun programming project. Operation spamst...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2003 01:27 PM
12-16-2003 01:27 PM
I've compiled it all by hand.
I got the bright idea to create am account on my server called spam.
I forward all unsolicited emails to that account.
I'm attaching a nice sample file.
I have processed it as follows and need help to accomplish my goals.
cat filename | grep -i recieved
gets this data.
Received: (from invest@localhost)
Received: from met.police.uk (modemcable090.154-70-69.mc.videotron.ca [69.70.154.90])
Received: from 102.183.181.197 by smtp.jur.kun.nl;
Received: (from invest@localhost)
Received: from wozenilek.de ([211.114.193.243])
Received: from 110.186.71.219 by smtp.cc.shibaura-it.ac.jp;
Received: (from invest@localhost)
Received: from dublinia.ie (OL186-15.fibertel.com.ar [24.232.15.186])
Received: from 34.83.110.48 by smtp.optifit.de;
Received: (from invest@localhost)
Received: from augddzpd.regenerousity.com ([65.208.147.35])
Received: from investmenttool.com (66.92.143.194)
Received: from yjuhr.regenerousity.com (HELO yjuhr) (169.254.98.41)
What I actually need is those numeric IP addresses.
My current format has me input into the access file this data:
169.254.98.41
169.254.98
This blocks the originating IP and its 255 class C address block. Its like using a nuclear weapon but thus far its been 95% effective.
Intended output is thus
169.254.98.41
Want a rabbit? Take this file and give me a shell script to give me my output. I'll insert the checks so none of yahoos mail servers and my mailservers end up getting blocked.
I know. I'm lazy, but I'm under the weather and tired of cut and paste.
I will test scripts prior to awarding points. All efforts get something.
If perl is better, go for it, I need those numeric IP addresses. I don't care about the domain name, most of those are forged anyway.
Regards,
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2003 07:07 PM
12-16-2003 07:07 PM
Re: A really fun programming project. Operation spamstopper!
cat filename | grep -i 'received' | perl -n -e 'print /.*[^0-9]([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)[^0-9].*/ ; print "\t\tWe charge $500 storage fee per unsolicited message.\n"' | grep '^[0-9]'
The latter will filter out errors due to lines not containing a IP addres...
Only lines it will fail are ones ending with an IP address, but since there are none in your example...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2003 07:25 PM
12-16-2003 07:25 PM
Re: A really fun programming project. Operation spamstopper!
perl -n -e 'if(/.*\D(\d+\.\d+\.\d+\.\d+).*/){print "$1\t\tWe charge $500 storage fee per unsolicited message\n"}' datafile
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2003 07:30 PM
12-16-2003 07:30 PM
Re: A really fun programming project. Operation spamstopper!
Please change the "$500" to "\$500" otherwise you'll be storing for free!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2003 12:06 AM
12-17-2003 12:06 AM
Re: A really fun programming project. Operation spamstopper!
i wanted to do it using shell-scripting. Not so nice and compact like perl, but an interesting exercise!
sed 's/[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*/X&X/g' BEASE_TEXT_FILE.txt | tr "X" "\012" | egrep [0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*
the above simple :) set of command extract the IP ADDRESS, the remainig is trivial....
MEGACOMMAND | while read IPADDR
do
echo "$IPADDR We charge \$500 storage fee per unsolicited message. "
done > YOUR_SUBSEQUENT_PROCESSING_CMD_FILE
Massimo
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2003 12:51 AM
12-17-2003 12:51 AM
Re: A really fun programming project. Operation spamstopper!
The shell route looks fun so
cat filename | grep -i received | while read a; do IP=`expr "$a" : ".*[^0-9]\([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*\)"`; [ $IP ] && /usr/bin/echo "$IP\t\tWe charge \$500 storage fee per unsolicited message."; done
Thi sdoe sthe whole thing in a one line shell script. The /usr/bin/echo is important because the shell builtin one doesn't interpret the \t as a tab.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2003 01:07 AM
12-17-2003 01:07 AM
Re: A really fun programming project. Operation spamstopper!
Your expr is very nice, i was looking for something similar but i didn't know, so i wordarounded...
Thanks for the lesson :)
Massimo
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2003 01:13 AM
12-17-2003 01:13 AM
Re: A really fun programming project. Operation spamstopper!
Actually, I don't think it's fool-proof but I think that given that SEP is grepping "received" lines from an e-mail we'll probably get away with it.
I thought about trying to get his exceptions list in there as well. I can feel it's a simple thing to do if we have a file of IP's that we don't charge for storage :) but I just can't see it !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2003 01:45 AM
12-17-2003 01:45 AM
Re: A really fun programming project. Operation spamstopper!
You have to be careful with automation....
What if someone has a case of fat finger syndrome - and mis-types your email address - I assume that if the user does not exist - then it goes to your spam account - and then you automatically block them!
I too block a lot of spam and have some pretty cool rules in place...
Rgds...Geoff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2003 01:53 AM
12-17-2003 01:53 AM
Re: A really fun programming project. Operation spamstopper!
When you cut and paste the script, keep in mind that its a 2 line script so you may have to join lines after the cut and paste.
Caveats 2 & 3:
In creating your original file you want to make sure you're only grabing the originator and not the poor guy grabbed on a hop.
Also, you may encourage them to send you more spam if you make them mad, though I salute your valor.
Here is the script:
grep [0123456789] $1 | sed -e"s/\[//g" -e"s/\]//g" -e "s/(//g" -e"s/)//g" > .um2
awk ' { for (idx1=1;idx1<=NF;idx1++) {if (match($idx1,"[0-9][0-9]*\.[0-9][0-9]*\
.[0-9][0-9]*\.[0-9][0-9]*")>0) {printf ("%s\t\t We charge $500 storage fee per u
nsolicited message\n",$idx1)};} }' <.um2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2003 02:09 AM
12-17-2003 02:09 AM
Re: A really fun programming project. Operation spamstopper!
Dec 17 07:13:46 myserver sendmail[2555]: hBHFDj9J002555:
Dec 17 07:13:46 myserver sendmail[2555]: hBHFDj9J002555: from=<>, size=3587, class=0, nrcpts=0, proto=ESMTP, daemon=MTA, relay=[213.86.143.191]
Sort of brute force guessing for users....
According to the RFC - I am not allowed to block from=<>
Anyone else have this issue?
I've thought of adding ip's to my iptables - and blocking there - cause with sendmail I am just wasting cpu...
SEP - sorry if I'm out of line posting in your thread - but I thought this was a good topic...
Rgds...Geoff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2003 03:45 AM
12-17-2003 03:45 AM
Re: A really fun programming project. Operation spamstopper!
I will test these today if possible. I don't have the file at work, but can obtain it via ftp.
I think there are very good applications for this utility once its done. That perl answer looks wonderful.
I think there are going to be a lot of rabbits hopping around this script.
Once I get something working, I'll award 10 points. Anything that tests out correctly but isn't used will get 9. If it fails on testing ,I'll be creative.
I may need additional help to have the script check a list of ips that can not be added to the bounce list(my dad's ip, my own ip block for example.).
I shall get back to you.
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2003 05:33 AM
12-17-2003 05:33 AM
Re: A really fun programming project. Operation spamstopper!
perl direct.pl < mailbox > iplist
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2003 05:42 AM
12-17-2003 05:42 AM
Re: A really fun programming project. Operation spamstopper!
I love it.
I may need to name a child after you.
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2003 05:56 AM
12-17-2003 05:56 AM
Re: A really fun programming project. Operation spamstopper!
###############################################################################
# validate IP address
###############################################################################
sub ValidateIPaddr {
############################################################################
# save the "passed" String IP address
############################################################################
my ($IPaddrSTR) = @_;
############################################################################
# validate the IP address - notes: ZERO (0) leading IP addresses are octal
# and we are NOT going to handle that - though it
# can easily be done - I consider that to be an
# error because system routines do not return IP's
# in octal string format!!! ie: 192.168.026.0 is
# NOT 192.168.26.0, it is 192.168.22.0 (decimal)
############################################################################
if( $IPaddrSTR !~ m/^ ( \d | 1?\d\d | 2[0-4]\d | 25[0-5] )
\. ( \d | 1?\d\d | 2[0-4]\d | 25[0-5] )
\. ( \d | 1?\d\d | 2[0-4]\d | 25[0-5] )
\. ( \d | 1?\d\d | 2[0-4]\d | 25[0-5] )
$
/xo) {
return(1); # wrong anwser
} else {
return(0);
}
}
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2003 06:30 AM
12-17-2003 06:30 AM
Re: A really fun programming project. Operation spamstopper!
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2003 08:55 AM
12-17-2003 08:55 AM
Re: A really fun programming project. Operation spamstopper!
I know that this is a STUPID script. But unfortunately it works :-(
for i in `cat ssk`
do
echo $i
done | grep [0-9].[0-9].[0-9].[0-9]|grep -v - | sed s/\(//g | sed s/\)//g | sed s/'\['//g | sed s/'\]'//g | sed s/\$/"`echo "\t\t"`We charge \$500 storage fee per unsolicited message."/g
And the output comes like this,
69.70.154.90 We charge $500 storage fee per unsolicited message.
102.183.181.197 We charge $500 storage fee per unsolicited message.
211.114.193.243 We charge $500 storage fee per unsolicited message.
110.186.71.219 We charge $500 storage fee per unsolicited message.
24.232.15.186 We charge $500 storage fee per unsolicited message.
34.83.110.48 We charge $500 storage fee per unsolicited message.
65.208.147.35 We charge $500 storage fee per unsolicited message.
66.92.143.194 We charge $500 storage fee per unsolicited message.
169.254.98.41 We charge $500 storage fee per unsolicited message.
-Karthik S S
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2003 08:59 AM
12-17-2003 08:59 AM
Re: A really fun programming project. Operation spamstopper!
69.70.154.90 We charge $500 storage fee per unsolicited message.
102.183.181.197 We charge $500 storage fee per unsolicited message.
-Karthik S S
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2003 09:14 AM
12-17-2003 09:14 AM
Re: A really fun programming project. Operation spamstopper!
I can do it with perl.
I can do it whiled standing on my head or sitting down.
This is truly a wonderful forum and I'm going to be a better shell programmer and perl programmer.
I'm going to combine the concepts and create a perl version I can run via the web and a shell version.
I'm going to add a check for a list of IP adresses to not ban, and build in the part that writes a second line knocking out the entire class C block the spam came from.
I know its a nuclear weapon, but it is powerful.
I'm under the weather and have maintenance until late this evening. I'll try and turn this around and hand out those rabbits before close of business Thursday.
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2003 09:16 AM
12-17-2003 09:16 AM
Re: A really fun programming project. Operation spamstopper!
Karthik S S
I missed your congrats thread.
Congrats.
Nice hat.
Enjoy Hogwarts.
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2003 09:30 AM
12-17-2003 09:30 AM
Re: A really fun programming project. Operation spamstopper!
Thanks a lot ... I feel great that I am getting noticed by one of the forum greats :-)
-Karthik S S
No points please ...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2003 11:20 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2003 01:35 PM
12-17-2003 01:35 PM
Re: A really fun programming project. Operation spamstopper!
Don't tell anyone, I'm testing on Linux. Its a language project.
Geoff Wild: Share your nice spam rules. Get an additional bunny rabbit. Will be awarding soon.
Patience.
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2003 03:28 PM
12-17-2003 03:28 PM
Re: A really fun programming project. Operation spamstopper!
I messed $IPB line for a while.
What I want it to do is this:
If the IP line outputs 192.168.0.15
I want the IPB line to ouput 192.168.0
B stands for block.
Believe it or not I can't figure it out.
In Linux shell scripting the tabs come out as \t. This is a Linux issue and I'll go to that forum for help there.
The \t comes out as a proper tab with the Korn shell and HP-UX
Linux version. HP-UX working version uses /usr/bin/ksh
#!/bin/sh
INPUTFILE=/var/mail/spam
TFILE1=/tmp/spam1.$$.dat
TFILE2=/tmp/spam2.$$.dat
cat $INPUTFILE | grep -i received > $TFILE1
while read LINE
do
IP=`expr "${LINE}" : ".*[^0-9]\([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*\).*"`
IPB=`expr "${LINE}" : ".*[^0-9]\([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*\).*"`
if [ ${?} -eq 0 ]
then
echo ${IP} "\t\tWe charge \$900 storage fee per unsolicited message." >> $TFILE2
# echo ${IPB} "\t\tWe charge \$900 storage fee per unsolicited message." >> $TFILE2
fi
done < $TFILE1
I'm handing out points to those whose scripts I've tested. If you don't get a rabbit testing did not produce proper output.
Karthik SS's sed version produced a little more than IP addresses.
This is the output
Received:
from
met.police.uk
(modemcable090.154-70-69.mc.videotron.ca
[69.70.154.90])
Received:
from
It was hard work. This is so much fun I'm going to keep trying until I've tested everyone's work.
That will take time so be patient. I may be acting anal, but I think its important to test the scripts and give rabbbits to those that produce near perfect output.
I'm having fun. How about you?
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2003 03:34 PM
12-17-2003 03:34 PM
Re: A really fun programming project. Operation spamstopper!
The spam mailbox is created by manual forwarding. I'm doing it now and I manually review messages sent by my various customers.
There is no totally automated method. Everyone gets one shot at my customers. The real problem is someone pulled my personnel address, maybe from forums and sold it widely. I think the two mouse clicks it takes to forward it to spam@mydomain.com is worth the effort.
I've been getting lazy about doing via cut and paste. After the manual operation sometimes I don't get spam at all for 7 days. Thats why nailing the entire Class C address block is important.
I'm working bottom to top(don't know why) Harry's perl code is worth a bunny and I may integrate it into one of the other perl scripts.
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com