0

hi everyone
my rule ıs /sbin/iptables -A INPUT -p tcp --dport 111 -j DROP
and ı want to forbıd tıll the port no 800.and ı donw want to wirte ıt down one by one.
so ı want to make a loop that wıll change port adress(whıch ıs 111) add port num

so far ı trıed slıcıng and counter=0 and counter +1 ın the loop
ıt gave me error
algorıtm ı treıd ıs

for x in range(800):
for x in iptables:
          counter +=x[39:4]
       print counter

and ıt gıves me error normally

so how can ı make ıt happen

out put should be


/sbin/iptables -A INPUT -p tcp --dport 111 -j DROP
/sbin/iptables -A INPUT -p tcp --dport 112 -j DROP
/sbin/iptables -A INPUT -p tcp --dport 113 -j DROP
/sbin/iptables -A INPUT -p tcp --dport 114 -j DROP
and so on

thanks for your hep

Edited by Nick Evan: Added code-tags

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by jlm699
0

ı want to make a loop that wıll change port adress

Here's a simple loop generating your example output strings between 111 and 115. I'm sure you can figure out how to extend up to 800.

>>> for x in xrange(111, 115):
...     print '/sbin/iptables -A INPUT -p tcp --dport %s -j DROP' % x
...     
/sbin/iptables -A INPUT -p tcp --dport 111 -j DROP
/sbin/iptables -A INPUT -p tcp --dport 112 -j DROP
/sbin/iptables -A INPUT -p tcp --dport 113 -j DROP
/sbin/iptables -A INPUT -p tcp --dport 114 -j DROP
>>>

HTH

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.