Git Product home page Git Product logo

iptables_parser's Introduction

iptables-parser

Documentation

Parse lines generated by iptables-save. This parser is inspired by Ben Johnson's SQL Parser.

Description

This parser parses lines returned from iptables-save or iptables -S and returns a Line or an Error. A Line can be a Rule, Comment, Policy (default rule) or Header, all of them being structs.

Match Extensions

iptables has a lot of match extensions. Only a few are implemented. If one is not implemented, the parses returns an error for that line.

Target Extensions

Just like in Match Extensions, not all of the target extensions are implemented.

Example

package main

import (
	"fmt"
	"log"

	ipt "github.com/coreos/go-iptables/iptables"
	iptp "github.com/kilo-io/iptables_parser"
)

func main() {
	t, err := ipt.NewWithProtocol(ipt.ProtocolIPv4)
	if err != nil {
		log.Fatal(err.Error())
	}
	rs, err := t.List("filter", "DOCKER")
	if err != nil {
		log.Fatal(err.Error())
	}
	for _, r := range rs {
		fmt.Println(r)
		tr, err := iptp.NewFromString(r)
		if err != nil {
			fmt.Printf("Error: %v", err)
			continue
		}
		switch r := tr.(type) {
		case iptp.Rule:
			fmt.Printf("rule parsed: %v\n", r)
		case iptp.Policy:
			fmt.Printf("policy parsed: %v\n", r)
		default:
			fmt.Printf("something else happend: %v\n", r)
		}

	}
}

iptables_parser's People

Contributors

adphi avatar cgroschupp avatar leonnicolas avatar meschenbacher avatar squat 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.