Skip to content

Commit

Permalink
-o flag: extract only selected types
Browse files Browse the repository at this point in the history
  • Loading branch information
assafmo committed Jan 20, 2019
1 parent c5a5c16 commit fb6d797
Showing 1 changed file with 34 additions and 5 deletions.
39 changes: 34 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ import (
"fmt"
"log"
"os"
"strings"

"github.com/assafmo/xioc/xioc"
)

type extractFunction func(text string) []string

var functions = map[string]extractFunction{
var availableFunctions = map[string]extractFunction{
"domain": xioc.ExtractDomains,
"email": xioc.ExtractEmails,
"ip4": xioc.ExtractIPv4s,
Expand All @@ -23,24 +24,52 @@ var functions = map[string]extractFunction{
"sha256": xioc.ExtractSHA256s,
}

const version = "1.0.0"
const version = "1.1.0"

var isPrintVersion bool
var versionFlag bool
var onlyFlag string

func init() {
flag.BoolVar(&isPrintVersion, "v", false, "Print version and exit")
flag.BoolVar(&versionFlag, "v", false, "Print version and exit")
flag.StringVar(&onlyFlag, "o", "", `Extract only specified types.
Types must be comma seperated. E.g: xioc -o "ip4,domain,url,md5"
Available types:
- ip4
- ip6
- domain
- url
- email
- md5
- sha1
- sha256`)

flag.Parse()
}

func main() {
// if -v flag, print version and exit
if isPrintVersion {
if versionFlag {
fmt.Printf("xioc v%s\n\n", version)
fmt.Println("Extract domains, ips, urls, emails, md5, sha1 and sha256 from text.")
fmt.Println("For more info visit https://github.com/assafmo/xioc")
return
}

functions := availableFunctions
if onlyFlag != "" {
functions = map[string]extractFunction{}

types := strings.Split(onlyFlag, ",")
for _, t := range types {
if f, ok := availableFunctions[t]; ok {
functions[t] = f
} else {
fmt.Printf(`Unknown extraction type "%s"`+"\n", t)
os.Exit(1)
}
}
}

fi, _ := os.Stdin.Stat()

if (fi.Mode() & os.ModeCharDevice) != 0 {
Expand Down

0 comments on commit fb6d797

Please sign in to comment.