add ip addr option

This commit is contained in:
xvzc 2022-05-08 14:39:35 +09:00
parent be4cf5366a
commit dd80adb448
4 changed files with 19 additions and 11 deletions

View File

@ -13,9 +13,9 @@ import (
) )
func main() { func main() {
port, dns, debug := util.ParseArgs() addr, port, dns, debug := util.ParseArgs()
p := proxy.New(port) p := proxy.New(addr, port)
doh.Init(dns) doh.Init(dns)
if debug { if debug {
log.SetLevel(log.DebugLevel) log.SetLevel(log.DebugLevel)
@ -27,7 +27,7 @@ func main() {
FullTimestamp: true, FullTimestamp: true,
}) })
util.PrintWelcome(port, dns, debug) util.PrintWelcome(addr, port, dns, debug)
if err := util.SetOsProxy(port); err != nil { if err := util.SetOsProxy(port); err != nil {
log.Fatal(err) log.Fatal(err)

View File

@ -1,9 +1,9 @@
package net package net
import ( import (
"errors"
"net" "net"
"time" "time"
"errors"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"github.com/xvzc/SpoofDPI/doh" "github.com/xvzc/SpoofDPI/doh"

View File

@ -11,20 +11,26 @@ import (
type Proxy struct { type Proxy struct {
port string port string
addr string
} }
func New(port string) *Proxy { func New(addr string, port string) *Proxy {
return &Proxy{ return &Proxy{
addr: addr,
port: port, port: port,
} }
} }
func (p *Proxy) TcpAddr() string {
return p.addr + ":" + p.port
}
func (p *Proxy) Port() string { func (p *Proxy) Port() string {
return p.port return p.port
} }
func (p *Proxy) Start() { func (p *Proxy) Start() {
l, err := net.Listen("tcp", "127.0.0.1:"+p.Port()) l, err := net.Listen("tcp", p.TcpAddr())
if err != nil { if err != nil {
log.Fatal("Error creating listener: ", err) log.Fatal("Error creating listener: ", err)
os.Exit(1) os.Exit(1)

View File

@ -7,22 +7,24 @@ import (
"github.com/pterm/pterm" "github.com/pterm/pterm"
) )
func ParseArgs() (string, string, bool) { func ParseArgs() (string,string, string, bool) {
addr := flag.String("addr", "127.0.0.1", "Listen addr")
port := flag.String("port", "8080", "port") port := flag.String("port", "8080", "port")
dns := flag.String("dns", "8.8.8.8", "DNS server") dns := flag.String("dns", "8.8.8.8", "DNS server")
debug := flag.Bool("debug", false, "true | false") debug := flag.Bool("debug", false, "true | false")
flag.Parse() flag.Parse()
return *port, *dns, *debug return *addr, *port, *dns, *debug
} }
func PrintWelcome(port string, dns string, debug bool) { func PrintWelcome(addr, port string, dns string, debug bool) {
cyan := pterm.NewLettersFromStringWithStyle("Spoof", pterm.NewStyle(pterm.FgCyan)) cyan := pterm.NewLettersFromStringWithStyle("Spoof", pterm.NewStyle(pterm.FgCyan))
purple := pterm.NewLettersFromStringWithStyle("DPI", pterm.NewStyle(pterm.FgLightMagenta)) purple := pterm.NewLettersFromStringWithStyle("DPI", pterm.NewStyle(pterm.FgLightMagenta))
pterm.DefaultBigText.WithLetters(cyan, purple).Render() pterm.DefaultBigText.WithLetters(cyan, purple).Render()
pterm.DefaultBulletList.WithItems([]pterm.BulletListItem{ pterm.DefaultBulletList.WithItems([]pterm.BulletListItem{
{Level: 0, Text: "ADDR : " + addr},
{Level: 0, Text: "PORT : " + port}, {Level: 0, Text: "PORT : " + port},
{Level: 0, Text: "DNS : " + dns}, {Level: 0, Text: "DNS : " + dns},
{Level: 0, Text: "DEBUG : " + fmt.Sprint(debug)}, {Level: 0, Text: "DEBUG : " + fmt.Sprint(debug)},