Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #45913
| Path | csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <davea@davea.name> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.005 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'subject:not': 0.03; 'output': 0.05; 'subject:file': 0.07; 'input,': 0.09; 'output,': 0.09; 'skip:o 50': 0.09; 'todo:': 0.09; 'better?': 0.16; 'blocks': 0.16; 'chris,': 0.16; 'flush': 0.16; 'subject:txt': 0.16; 'timestamp': 0.16; 'wrote:': 0.18; 'bit': 0.19; 'command': 0.22; 'input': 0.22; 'import': 0.22; 'rules': 0.22; 'header:User- Agent:1': 0.23; 'skip:l 30': 0.24; 'header:In-Reply-To:1': 0.27; "skip:' 10": 0.31; 'file': 0.32; 'skip:# 10': 0.33; 'version': 0.36; 'skip:o 20': 0.38; 'subject:new': 0.38; 'to:addr:python- list': 0.38; 'pm,': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'changed': 0.39; 'read': 0.60; 'skip:t 30': 0.61; 'protection': 0.63; 'received:74.208': 0.68; "'with'": 0.84; 'received:74.208.4.194': 0.84; 'stamp': 0.91; 'subject:add': 0.91 |
| Date | Fri, 24 May 2013 15:29:27 -0400 |
| From | Dave Angel <davea@davea.name> |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130510 Thunderbird/17.0.6 |
| MIME-Version | 1.0 |
| To | python-list@python.org |
| Subject | Re: Read txt file, add to iptables not working on new host |
| References | <puAnt.800936$OJ2.639894@en-nntp-11.dc1.easynews.com> <mailman.2067.1369403653.3114.python-list@python.org> <FCMnt.5938$4E1.5852@en-nntp-08.dc1.easynews.com> |
| In-Reply-To | <FCMnt.5938$4E1.5852@en-nntp-08.dc1.easynews.com> |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Provags-ID | V02:K0:ti3ZAWLszXtp1zIynzwqYtJ8clJTkzebAJM9/bgckUe cNlbJ5JBuTGywPhXuQEBxDF7xuBeaq5Y2Rk5MuCIB0F5YGrbjF 104s7pS4/cpoPVgSMk+NngwBqtqzAKChsn5dd3URskE+D/blVn XKa2G/Mhv2l66twg28IlNqnDO+YMF7WqVkTt6HckNoP7Y9v8R8 YAGiSQKp0ODr0WyaujgcM9bdYrneyF7rkXhoQofrPvINvgaCKv sAhsWxVlTLPtXZ6QWNTTfyc9CD5mQd0TFRqVehLGFr1IY8+aLJ 3P3ttg0CtZ6Yl8VOasZi4NHcQuXbfEJKGG790E6PxUbub2wlx1 mrL5ZT+hhDpOuG+6ZM78= |
| 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.2075.1369423780.3114.python-list@python.org> (permalink) |
| Lines | 35 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1369423780 news.xs4all.nl 15973 [2001:888:2000:d::a6]:55610 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:45913 |
Show key headers only | View raw
On 05/24/2013 12:32 PM, JackM wrote:
> So Chris, does this version look better? Changed to inFile to with.
>
>
> #!/usr/bin/python
> import os
> import time
>
> # Input, Output, and TimeStamp
> logFile = open('/var/www/html/statistics/logs/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+'\nFlushing Rules..\n')
>
> # Loop to read in file and Apply rules to IPtables
> with open('/var/www/html/mydomain.com/banlist.txt','r') as inFile:
> for line in inFile: # TODO: Use 'with' for a bit of protection
> ip = line.split(';')[0]
You want to write the command to the logfile here, BEFORE you try the
popen(). That way if there's a problem, you can see what it was about
to try before it crashed.
> output = os.popen( '/sbin/iptables -A INPUT -s ' + ip + ' -j
> REJECT' )
> logFile.write(ip+' - Has been blocked\n')
>
>
>
>
--
DaveA
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll 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