Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #45863
| From | Carlos Nepomuceno <carlosnepomuceno@outlook.com> |
|---|---|
| Subject | RE: Read txt file, add to iptables not working on new host |
| Date | 2013-05-24 06:10 +0300 |
| References | <puAnt.800936$OJ2.639894@en-nntp-11.dc1.easynews.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2048.1369365052.3114.python-list@python.org> (permalink) |
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 | Next — Previous in thread | Next 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