Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Research: <a href="https://wiki.debian.org/iptables" rel="nofollow">https://wiki.debian.org/iptables</a></p> <p>Example of iptables-save binary:</p> <pre><code>$ sudo iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT $ sudo iptables -L -v Chain INPUT (policy ACCEPT 5 packets, 224 bytes) pkts bytes target prot opt in out source destination 162 26863 ACCEPT all -- any any anywhere anywhere state RELATED,ESTABLISHED Chain FORWARD (policy ACCEPT 0 packets, 0 bytes) pkts bytes target prot opt in out source destination Chain OUTPUT (policy ACCEPT 185 packets, 31967 bytes) pkts bytes target prot opt in out source destination $ sudo /sbin/iptables-save # Generated by iptables-save v1.4.7 on Mon Nov 18 11:43:19 2013 *filter :INPUT ACCEPT [8:432] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [699:111055] -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT COMMIT # Completed on Mon Nov 18 11:43:19 2013 </code></pre> <p>PHP Code:</p> <pre><code>&lt;?php // get content from command called $processHandle = popen('/usr/bin/sudo /sbin/iptables-save 2&gt;&amp;1', 'r'); $content = ''; while (!feof($processHandle)) { $content .= fread($processHandle, 4096); } pclose($processHandle); // break out all new lines into an array $lines = explode("\n", $content); // parse through each line $commands = ''; foreach ($lines as $line) { if (empty($line)) { continue; } if (preg_match('/^#/', $line) === 1) { continue; } if (preg_match('/^\*/', $line) === 1) { continue; } if (preg_match('/^COMMIT/', $line) === 1) { continue; } $match = array(); if (preg_match('/^:([A-Z ]*).*/', $line, $match) === 1) { //echo "iptables -P {$match[1]}\n"; continue; } $commands .= "iptables {$line}\n"; } // write to a results file $fileHandle = fopen("results", "w"); fwrite($fileHandle, $commands); fclose($fileHandle); ?&gt; </code></pre> <p>Runtime output:</p> <pre><code>$ php test3.php iptables -P INPUT ACCEPT iptables -P FORWARD ACCEPT iptables -P OUTPUT ACCEPT iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload