SpoofDPI/util/util.go

58 lines
1.7 KiB
Go
Raw Normal View History

2021-12-29 17:08:30 +00:00
package util
import (
2022-01-08 15:48:19 +00:00
"flag"
2022-01-10 14:58:27 +00:00
"fmt"
"github.com/pterm/pterm"
2021-12-29 17:08:30 +00:00
)
type ArrayFlags []string
func (i *ArrayFlags) String() string {
return "my string representation"
}
func (i *ArrayFlags) Set(value string) error {
*i = append(*i, value)
return nil
}
func ParseArgs() (string, int, string, bool, bool, *ArrayFlags, string) {
2022-05-08 05:39:35 +00:00
addr := flag.String("addr", "127.0.0.1", "Listen addr")
2022-05-13 09:49:05 +00:00
port := flag.Int("port", 8080, "port")
2022-01-08 15:48:19 +00:00
dns := flag.String("dns", "8.8.8.8", "DNS server")
debug := flag.Bool("debug", false, "true | false")
2022-07-24 02:20:23 +00:00
banner := flag.Bool("banner", true, "true | false")
2022-01-08 15:48:19 +00:00
var allowedUrls ArrayFlags
flag.Var(&allowedUrls, "url", "Bypass DPI only on this url, can be passed multiple times")
allowedPattern := flag.String("pattern", "", "Bypass DPI only on packets matching this regex pattern")
2022-01-08 15:48:19 +00:00
flag.Parse()
2022-01-03 07:24:39 +00:00
return *addr, *port, *dns, *debug, *banner, &allowedUrls, *allowedPattern
2022-01-03 07:24:39 +00:00
}
2022-01-03 15:13:42 +00:00
2022-07-24 02:20:23 +00:00
func PrintColoredBanner(addr string, port int, dns string, debug bool) {
2022-01-10 14:58:27 +00:00
cyan := pterm.NewLettersFromStringWithStyle("Spoof", pterm.NewStyle(pterm.FgCyan))
purple := pterm.NewLettersFromStringWithStyle("DPI", pterm.NewStyle(pterm.FgLightMagenta))
pterm.DefaultBigText.WithLetters(cyan, purple).Render()
pterm.DefaultBulletList.WithItems([]pterm.BulletListItem{
2022-05-08 05:39:35 +00:00
{Level: 0, Text: "ADDR : " + addr},
2022-05-13 09:49:05 +00:00
{Level: 0, Text: "PORT : " + fmt.Sprint(port)},
2022-01-10 14:58:27 +00:00
{Level: 0, Text: "DNS : " + dns},
{Level: 0, Text: "DEBUG : " + fmt.Sprint(debug)},
}).Render()
}
2022-07-24 02:20:23 +00:00
func PrintSimpleInfo(addr string, port int, dns string, debug bool) {
2022-11-29 07:54:28 +00:00
fmt.Println("")
fmt.Println("- ADDR : ", addr)
fmt.Println("- PORT : ", port)
fmt.Println("- DNS : ", dns)
fmt.Println("- DEBUG : ", debug)
fmt.Println("")
2022-07-24 02:20:23 +00:00
}