Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/philipjscott/plisten

Register callback functions that trigger on tcp/udp requests.
https://github.com/philipjscott/plisten

Last synced: about 1 month ago
JSON representation

Register callback functions that trigger on tcp/udp requests.

Awesome Lists containing this project

README

        

# plisten

Register callback functions that trigger on tcp/udp requests. Currently only supports DNS; I may add more functionality in the future.

## Documentation

The godoc can be found here: https://godoc.org/github.com/ScottyFillups/plisten/pkg/dnsl

## Installation

The binary provided in `cmd/` is currently just a DNS sniffer that logs requests; in the future I'm considering making a CLI for sniffing different layers (eg. HTTP)

```
go get github.com/ScottyFillups/plisten/cmd/plisten
```

If `$GOPATH/bin` is in your `$PATH`, then you can invoke the binary:

```
sudo plisten
```

## Usage

```go
package main

import (
"github.com/ScottyFillups/plisten/pkg/dnsl"
"fmt"
"log"
)

func logDNSWarn(d *dnsl.DNSListener, match string) {
fmt.Println("You visited: " + match + ". Shouldn't you be working?")
}

func main() {
dataChan := make(chan dnsl.Packet)
dl := dnsl.New()

err := dl.Listen(dataChan)
if err != nil {
log.Fatal("Failed to initialize DNS listener")
}

err = dl.Register(".*facebook.*", logDNSWarn)
if err != nil {
log.Fatal("Failed to compile regexp")
}

for data := range dataChan {
if data.Error != nil {
fmt.Println(data.Error)
dl.Close()
break
}

fmt.Println(data.Host)
}
}
```

See `/examples` for more specific and creative usages.