Skip to content

Commit

Permalink
Add cli
Browse files Browse the repository at this point in the history
  • Loading branch information
qba73 committed Mar 22, 2024
1 parent 9dd227e commit 7ea0198
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

# hpot

`hpot` is a Go library and a CLI and TUI honeypot application.
`hpot` is a Go CLI HoneyPot application.
13 changes: 6 additions & 7 deletions cmd/hpot/main.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package main

import "github.com/qba73/hpot"
import (
"os"

func main() {
pot := hpot.NewHoneyPotServer()
pot.Ports = []int{8081, 8082}
"github.com/qba73/hpot"
)

if err := pot.ListenAndServe(); err != nil {
panic(err)
}
func main() {
os.Exit(hpot.Main())
}
47 changes: 47 additions & 0 deletions hpot.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package hpot

import (
"flag"
"fmt"
"net"
"net/http"
"os"
"strconv"
"strings"
"sync"
)

Expand Down Expand Up @@ -90,3 +93,47 @@ func (p *Pot) serve(l net.Listener) {
conn.Close()
}
}

func parsePorts(ports string) ([]int, error) {
var prts []int
px := strings.Split(ports, ",")
for _, p := range px {
p = strings.TrimSpace(p)
pr, err := strconv.Atoi(p)
if err != nil {
return nil, err
}
prts = append(prts, pr)
}
return prts, nil
}

var usage = `Usage: hpot [-v] port,port,port
Start the HopneyPot and listen on incoming connections on provided, coma separated ports.
In verbose mode (-v), reports all incoming connections.`

func Main() int {
verbose := flag.Bool("v", false, "verbose output")
flag.Parse()
if len(flag.Args()) == 0 {
fmt.Println(usage)
return 0
}

ports, err := parsePorts(flag.Args()[0])
if err != nil {
fmt.Println(usage)
return 1
}

pot := NewHoneyPotServer()
pot.Verbose = *verbose
pot.Ports = ports

if err := pot.ListenAndServe(); err != nil {
return 1
}
return 0
}

0 comments on commit 7ea0198

Please sign in to comment.