Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #45913
| Date | 2013-05-24 15:29 -0400 |
|---|---|
| From | Dave Angel <davea@davea.name> |
| 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> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2075.1369423780.3114.python-list@python.org> (permalink) |
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