Giter Site home page Giter Site logo

lcfcosta / iptables.net Goto Github PK

View Code? Open in Web Editor NEW

This project forked from splitice/iptables.net

0.0 1.0 0.0 1.92 MB

A library for for interfacing C# with Linux IPTables, Conntrack & IP Utils

License: The Unlicense

C# 73.54% C 23.10% Shell 0.28% Makefile 0.82% C++ 2.26%

iptables.net's Introduction

IPTables.Net

Build Status

A library for for interfacing C# with Linux IPTables

Features

  • String rule parsing to class based representation
  • IPTables save rule parsing from either a local or remote system (SSH via SystemInteract.Remote)
  • Automatic Synchronization of rules with system (Insert, Delete, Replace)
  • IPSet support
  • Support for both IPv4 and IPv6

Adapters

An adapter is used to communicate with IPTables. Depending on your implementation / requirements you may wish to choose a specific adapter.

IPTables Binary

This is the most simple adapter and the default. It does not have any transactional support (make many changes at once) and is not high performing when making many changes and dealing with complex rule sets. This adapter requires only the iptables-save and iptables binaries to work.

IPTables Restore

This is a bit more advanced instead of using iptables, iptables-restore is used. This provides transactions on a per-table basis and higher performance. Unfortunately due to how iptables-restore is implemented this adapter does not play nice with other rules loaded outside of this script unless the patch supplied is applied (which is specific to an IPTables version).

IPTables Library

This is the most advanced method. Supports transactions and is very high performing. This method uses a custom shared library to communicate and control libiptc directly. No need for any iptables binaries (when in a transaction). The library iptchelper needs to be compiled, if compiling on an IPTables version less than 1.4.18 (ish) you will need to supply the pre-processor macro OLD_IPTABLES for the compilation to succeed. See the travis file for an example on how to provide this option, and how to compile the library. install.sh has been provided as a one click installer for new IPTables versions.

This method is only compatible locally, will not work over SSH (SystemInteract.Remote).

Examples

For more examples see the Tests project. These are generally more full featured and up-to-date.

Parsing an IPTables Rule:

String rule = "-A INPUT -p tcp ! -f -j DROP -m tcp --sport 53 -m comment --comment 'this is a test rule'";
IpTablesChainSet chains = new IpTablesChainSet();
IpTablesRule irule = IpTablesRule.Parse(rule, null, chains);

Deleting all defined rules:

var system = new IPTablesSystem();
foreach(var rule in system.GetRules("nat")){
    rule.Delete();
}

Syncing a chain set:

IpTablesChain chain = new IpTablesChain("filter","INPUT",system); 
chain.AddRule("-A INPUT !-f"); 
system.GetChain("filter","INPUT").Sync(chain);

Contributing

Pull-Requests and Patches are very welcome.

iptables.net's People

Contributors

splitice avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.