Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #45863

RE: Read txt file, add to iptables not working on new host

Path csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <carlosnepomuceno@outlook.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'subject:not': 0.03; 'argument': 0.05; 'output': 0.05; 'great.': 0.07; 'hosts': 0.07; 'skip:` 10': 0.07; 'subject:file': 0.07; 'output,': 0.09; 'skip:/ 10': 0.09; 'skip:o 50': 0.09; 'tmp': 0.09; 'runs': 0.10; 'python': 0.11; "'),": 0.16; 'blocked': 0.16; 'blocks': 0.16; 'command.': 0.16; 'flush': 0.16; 'subject:txt': 0.16; 'timestamp': 0.16; 'file,': 0.19; 'thu,': 0.19; 'thanks.': 0.20; 'written': 0.21; 'input': 0.22; 'import': 0.22; 'rules': 0.22; 'to:name:python- list@python.org': 0.22; 'error': 0.23; 'entries': 0.24; 'received:65.55.116': 0.24; 'skip:l 30': 0.24; 'header': 0.24; 'server.': 0.24; 'script': 0.25; 'first,': 0.26; 'header:In-Reply- To:1': 0.27; 'host': 0.29; 'skip:- 40': 0.29; 'points': 0.29; 'errors': 0.30; 'involving': 0.30; 'url:mailman': 0.30; 'getting': 0.31; "skip:' 10": 0.31; 'catching': 0.31; 'txt': 0.31; 'file': 0.32; "we're": 0.32; 'text': 0.33; 'worked': 0.33; 'url:python': 0.33; 'addresses': 0.33; 'skip:# 10': 0.33; 'date:': 0.34; 'could': 0.34; 'knowledge': 0.35; 'add': 0.35; 'tech': 0.36; 'url:listinfo': 0.36; 'url:org': 0.36; 'email addr:python.org': 0.37; 'skip:o 20': 0.38; 'subject:new': 0.38; 'to:addr:python- list': 0.38; 'subject:': 0.39; 'bad': 0.39; 'skip:8 10': 0.39; 'to:addr:python.org': 0.39; 'changed': 0.39; 'url:mail': 0.40; 'remove': 0.60; 'read': 0.60; 'tell': 0.60; 'skip:o 30': 0.61; 'skip:t 30': 0.61; 'new': 0.61; 'address': 0.63; 'reached': 0.63; 'skip:n 10': 0.64; 'more': 0.64; 'email name:python-list': 0.65; 'url:htm': 0.73; 'account.': 0.80; 'again?': 0.84; '2013,': 0.91; 'stamp': 0.91; 'subject:add': 0.91; '2013': 0.98
X-TMN [RHR8PCU8skaGUHkmJ7+3474ZTDDKpjKJ]
X-Originating-Email [carlosnepomuceno@outlook.com]
From Carlos Nepomuceno <carlosnepomuceno@outlook.com>
To "python-list@python.org" <python-list@python.org>
Subject RE: Read txt file, add to iptables not working on new host
Date Fri, 24 May 2013 06:10:48 +0300
Importance Normal
In-Reply-To <puAnt.800936$OJ2.639894@en-nntp-11.dc1.easynews.com>
References <puAnt.800936$OJ2.639894@en-nntp-11.dc1.easynews.com>
Content-Type text/plain; charset="iso-8859-1"
Content-Transfer-Encoding quoted-printable
MIME-Version 1.0
X-OriginalArrivalTime 24 May 2013 03:10:48.0167 (UTC) FILETIME=[49E1E770:01CE582C]
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2048.1369365052.3114.python-list@python.org> (permalink)
Lines 83
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1369365052 news.xs4all.nl 15896 [2001:888:2000:d::a6]:56833
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:45863

Show key headers only | View raw


Send the output of the following commands:

uname -a
/sbin/iptables -V


----------------------------------------
> From: notreal@earthlink.net
> Subject: Read txt file, add to iptables not working on new host
> Date: Thu, 23 May 2013 22:44:38 -0400
> To: python-list@python.org
>
> First, let me say that I have no knowledge of or experience with Python
> or Linux/Unix. I have a script which was written by a host tech person
> that ran via cron on my old server. It was designed to read IP addresses
> from a text file and add them to be blocked on iptables. That way, we
> could add or remove IPs without involving tech support daily. It worked
> great.
>
> Then we changed hosts and this script is now throwing errors on the new
> server. This host runs Python 2.6.6. This is the script:
>
> #!/usr/bin/python
> import os,time
>
> ##Input, Output, and TimeStamp
> inFile = open('/var/www/html/mydomain.com/banlist.txt','r')
> logFile = open('/var/log/banList.log','w')
> stamp = time.asctime(time.localtime())
>
>
> ##Daily Flush of blockList rules before re-applying Blocks
> os.popen('/sbin/iptables -F INPUT')
> logFile.write(stamp), logFile.write('\n'), logFile.write('Flushing
> Rules..\n')
>
> ##Loop to read in file and Apply rules to IPtables
> for line in inFile.readlines():
> tmp = line.split(';')
> IP = tmp[0]
> outPut = os.popen( '/sbin/iptables -A INPUT -s' + ' ' + IP + ' ' + '-j
> REJECT' )
> logFile.write(IP), logFile.write(' - Has been blocked '),
> logFile.write(stamp),logFile.write
>
>
> The errors we're getting are like these:
>
> Bad argument `174.37.65.204'
> Try `iptables -h' or 'iptables --help' for more information.
> Bad argument `94.159.162.182'
> Try `iptables -h' or 'iptables --help' for more information.
> Bad argument `95.134.132.98'
> Try `iptables -h' or 'iptables --help' for more information.
> etc.
>
> Entries from the banlist.txt are like these:
>
> 200.193.54.138; February 9, 2013, 7:42 am <br>
> 87.120.57.4; February 9, 2013, 7:42 am <br>
> 82.206.129.160; February 9, 2013, 7:43 am <br>
> etc.
>
> I know the error points to a bad iptables command.
> Can someone tell me what change(s) I need to make to this script to get
> it working again? Thanks.
>
>
>
> --
> My email address on the header is a non-monitored spam catching account.
> I can be reached via http://www.wvnh.net/contact.htm
>
> --
> http://mail.python.org/mailman/listinfo/python-list 		 	   		  

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Read txt file, add to iptables not working on new host JackM <notreal@earthlink.net> - 2013-05-23 22:44 -0400
  RE: Read txt file, add to iptables not working on new host Carlos Nepomuceno <carlosnepomuceno@outlook.com> - 2013-05-24 06:10 +0300
    Re: Read txt file, add to iptables not working on new host JackM <notreal@earthlink.net> - 2013-05-24 09:08 -0400
      RE: Read txt file, add to iptables not working on new host Carlos Nepomuceno <carlosnepomuceno@outlook.com> - 2013-05-24 16:15 +0300
  Re: Read txt file, add to iptables not working on new host Chris Angelico <rosuav@gmail.com> - 2013-05-24 23:54 +1000
    Re: Read txt file, add to iptables not working on new host JackM <notreal@earthlink.net> - 2013-05-24 12:32 -0400
      Re: Read txt file, add to iptables not working on new host Chris Angelico <rosuav@gmail.com> - 2013-05-25 02:56 +1000
      Re: Read txt file, add to iptables not working on new host Dave Angel <davea@davea.name> - 2013-05-24 15:29 -0400

csiph-web