Skip to content

Commit 190ba81

Browse files
author
ldx
committed
Generate README.md from RST files in doc.
The command to update README.md: pandoc -f rst -t markdown doc/intro.rst doc/examples.rst -o README.md
1 parent 2cbd38d commit 190ba81

File tree

3 files changed

+95
-35
lines changed

3 files changed

+95
-35
lines changed

README.md

Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ command:
308308

309309
Counters
310310
--------
311+
311312
You can query rule and chain counters, e.g.:
312313

313314
>>> import iptc
@@ -317,36 +318,40 @@ You can query rule and chain counters, e.g.:
317318
>>> (packets, bytes) = rule.get_counters()
318319
>>> print packets, bytes
319320

320-
However, the counters are only refreshed when the underlying low-level iptables connection is refreshed in `Table` via `table.refresh()`. For example:
321-
322-
import time, sys
323-
import iptc
324-
table = iptc.Table(iptc.Table.FILTER)
325-
chain = iptc.Chain(table, 'OUTPUT')
326-
for rule in chain.rules:
327-
(packets, bytes) = rule.get_counters()
328-
print packets, bytes
329-
print "Please send some traffic"
330-
sys.stdout.flush()
331-
time.sleep(3)
332-
for rule in chain.rules:
333-
# Here you will get back the same counter values as above
334-
(packets, bytes) = rule.get_counters()
335-
print packets, bytes
336-
337-
This will show you the same counter values even if there was traffic hitting your rules. You have to refresh your table to get update your counters:
338-
339-
import time, sys
340-
import iptc
341-
table = iptc.Table(iptc.Table.FILTER)
342-
chain = iptc.Chain(table, 'OUTPUT')
343-
for rule in chain.rules:
344-
(packets, bytes) = rule.get_counters()
345-
print packets, bytes
346-
print "Please send some traffic"
347-
sys.stdout.flush()
348-
time.sleep(3)
349-
table.refresh() # Here: refresh table to update rule counters
350-
for rule in chain.rules:
351-
(packets, bytes) = rule.get_counters()
352-
print packets, bytes
321+
However, the counters are only refreshed when the underlying low-level
322+
iptables connection is refreshed in `Table` via `table.refresh()`. For
323+
example:
324+
325+
>>> import time, sys
326+
>>> import iptc
327+
>>> table = iptc.Table(iptc.Table.FILTER)
328+
>>> chain = iptc.Chain(table, 'OUTPUT')
329+
>>> for rule in chain.rules:
330+
>>> (packets, bytes) = rule.get_counters()
331+
>>> print packets, bytes
332+
>>> print "Please send some traffic"
333+
>>> sys.stdout.flush()
334+
>>> time.sleep(3)
335+
>>> for rule in chain.rules:
336+
>>> # Here you will get back the same counter values as above
337+
>>> (packets, bytes) = rule.get_counters()
338+
>>> print packets, bytes
339+
340+
This will show you the same counter values even if there was traffic
341+
hitting your rules. You have to refresh your table to get update your
342+
counters:
343+
344+
>>> import time, sys
345+
>>> import iptc
346+
>>> table = iptc.Table(iptc.Table.FILTER)
347+
>>> chain = iptc.Chain(table, 'OUTPUT')
348+
>>> for rule in chain.rules:
349+
>>> (packets, bytes) = rule.get_counters()
350+
>>> print packets, bytes
351+
>>> print "Please send some traffic"
352+
>>> sys.stdout.flush()
353+
>>> time.sleep(3)
354+
>>> table.refresh() # Here: refresh table to update rule counters
355+
>>> for rule in chain.rules:
356+
>>> (packets, bytes) = rule.get_counters()
357+
>>> print packets, bytes

doc/examples.rst

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,3 +210,51 @@ matches::
210210
This is the ``python-iptables`` equivalent of the following iptables command::
211211

212212
# iptables -A INPUT -p tcp –destination-port 22 -m iprange –src-range 192.168.1.100-192.168.1.200 –dst-range 172.22.33.106 -j DROP
213+
214+
Counters
215+
--------
216+
You can query rule and chain counters, e.g.::
217+
218+
>>> import iptc
219+
>>> table = iptc.Table(iptc.Table.FILTER)
220+
>>> chain = iptc.Chain(table, 'OUTPUT')
221+
>>> for rule in chain.rules:
222+
>>> (packets, bytes) = rule.get_counters()
223+
>>> print packets, bytes
224+
225+
However, the counters are only refreshed when the underlying low-level
226+
iptables connection is refreshed in ``Table`` via ``table.refresh()``. For
227+
example::
228+
229+
>>> import time, sys
230+
>>> import iptc
231+
>>> table = iptc.Table(iptc.Table.FILTER)
232+
>>> chain = iptc.Chain(table, 'OUTPUT')
233+
>>> for rule in chain.rules:
234+
>>> (packets, bytes) = rule.get_counters()
235+
>>> print packets, bytes
236+
>>> print "Please send some traffic"
237+
>>> sys.stdout.flush()
238+
>>> time.sleep(3)
239+
>>> for rule in chain.rules:
240+
>>> # Here you will get back the same counter values as above
241+
>>> (packets, bytes) = rule.get_counters()
242+
>>> print packets, bytes
243+
244+
This will show you the same counter values even if there was traffic hitting
245+
your rules. You have to refresh your table to get update your counters::
246+
247+
>>> import time, sys
248+
>>> import iptc
249+
>>> table = iptc.Table(iptc.Table.FILTER)
250+
>>> chain = iptc.Chain(table, 'OUTPUT')
251+
>>> for rule in chain.rules:
252+
>>> (packets, bytes) = rule.get_counters()
253+
>>> print packets, bytes
254+
>>> print "Please send some traffic"
255+
>>> sys.stdout.flush()
256+
>>> time.sleep(3)
257+
>>> table.refresh() # Here: refresh table to update rule counters
258+
>>> for rule in chain.rules:
259+
>>> (packets, bytes) = rule.get_counters()
260+
>>> print packets, bytes

doc/intro.rst

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,15 @@ Linux iptables framework..
3131

3232
.. |buildstatus| image:: https://travis-ci.org/ldx/python-iptables.png?branch=master
3333

34-
Compiling and installing
35-
------------------------
34+
Installing via pip
35+
------------------
36+
37+
The usual way::
38+
39+
pip install --upgrade python-iptables
40+
41+
Compiling from source
42+
----------------------
3643

3744
First make sure you have iptables installed (most Linux distributions install
3845
it by default). ``Python-iptables`` needs the shared libraries ``libiptc.so``

0 commit comments

Comments
 (0)