Results 1 to 4 of 4

Thread: Script Help: How to only get text between "[" and "]" on lines within a log file?

  1. #1
    nat
    nat is offline
    Member
    Join Date
    Jan 2003
    Posts
    210

    Default Script Help: How to only get text between "[" and "]" on lines within a log file?

    Someone is sending e-mail to

    aaaa@mydomain.com
    aaab@mydomain.com
    aaac@mydomain.com
    ....etc
    aaba@mydomain.com
    aabb@mydomain.com
    ....and so on.....

    This is INCOMING e-mail to the server. Not outgoing.

    The person doing this is using about 200 unique IPs every day.

    It is causing a high load on the server Even when I use :blackhole:

    If I could only get the ip addresses between the [ and ] from each line that contains the phrase "spam trap" in exim_mainlog, I could do the rest of the script that will automaticly block these IPs for me.


    Example:
    2004-09-10 05:13:40 H=(dsl-201-135-79-196.prod-infinitum.com.mx) [201.135.79.196] F=<mrebfuzbtrf@excite.it> rejected RCPT <nabd@mydomai.com>: you have sent e-mail to a spam trap. your e-mail has been discarded.

    2004-09-10 05:13:40 H=(dsl-201-135-79-196.prod-infinitum.com.mx) [201.135.79.196] F=<mrebfuzbtrf@excite.it> rejected RCPT <nabe@mydomai.com>: you have sent e-mail to a spam trap. your e-mail has been discarded.


    I need to be able to get the 201.135.79.196 between the [ and ] and ignore the rest? Can anyone help with a comand that can do this?




    PS:

    I am already using the following RBL's:
    sbl-xbl.spamhaus.org
    bl.spamcop.net
    relays.ordb.org
    cbl.abuseat.org
    blackholes.mail-abuse.org
    spam.dnsrbl.net
    opm.blitzed.org
    brazil.blackholes.us
    malaysia.blackholes.us
    china.blackholes.us

  2. #2
    Member
    Join Date
    Jun 2003
    Posts
    396

    Default

    How about something like this

    Code:
    #!/usr/local/bin/php
    
    <?
    // read from stdin (could be a filter)
    // Get the IP address from the folloowing line
    //2004-09-10 05:13:40 H=(dsl-201-135-79-196.prod-infinitum.com.mx) [201.135.79.19
    6] F=<mrebfuzbtrf@excite.it> rejected RCPT <nabe@mydomai.com>: you have sent e-ma
    il to a spam trap. your e-mail has been discarded.
    
    
    $fd = fopen("php://stdin", "r");
    $email = "";
    while (!feof($fd)) {
        $email .= fread($fd, 1024);
    }
    fclose($fd);
    
    $SUB = strstr($email, "RCPT");          // find the line we need
    $S = explode("]",$email);               // get everything before the ]
    $IP = explode("[",$S[0]);               // get everything before after the [
    
    echo $IP[1];                            // echo just the IP addres
    ?>
    -Albert

  3. #3
    Super Moderator This forum account has been confirmed by cPanel staff to represent a vendor. chirpy's Avatar
    Join Date
    Jun 2002
    Location
    Go on, have a guess
    Posts
    13,496

    Default

    The following one liner will do it:

    grep "rejected RCPT" /var/log/exim_mainlog | grep -P "\d+\.\d+\.\d+\.\d+" -o

    A better bet, though, would be to install a dictionary attack ACL (and switch to :fail: instead of :blackhole:):
    http://www.webumake.com/free/eximdeny.htm
    Last edited by chirpy; 09-10-2004 at 09:06 AM.
    Jonathan Michaelson

    Need your cPanel servers secured and tuned?
    cPanel Server Configuration, Security, Recovery and Antivirus/AntiSpam Services
    Developers of the most effective (and free) Firewall & Security Solution for cPanel Servers - csf
    http://www.configserver.com

  4. #4
    nat
    nat is offline
    Member
    Join Date
    Jan 2003
    Posts
    210

    Default

    Thanks all!

    The Dictionary Deny ACL script at http://www.webumake.com/free/eximdeny.htm is doing the job nicely. 42 IPs blocked within the last 10 minutes or so.

Similar Threads

  1. Replies: 8
    Last Post: 02-11-2011, 01:39 PM
  2. Changed system files - No info in "New" or "Chaneg Log"
    By aquagerbil in forum New User Questions
    Replies: 3
    Last Post: 09-22-2010, 09:50 AM
  3. "Leave DNS on server" option missing from reseller center "terminate accounts" page.
    By electric in forum Feature Requests for cPanel & WHM
    Replies: 3
    Last Post: 04-19-2010, 02:14 PM
  4. Change Log in text to "Full Email Address"
    By d-woo in forum cPanel & WHM Discussions
    Replies: 0
    Last Post: 06-11-2004, 11:30 PM