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

View File

@ -1,9 +1,9 @@
package net
import (
"errors"
"net"
"time"
"errors"
log "github.com/sirupsen/logrus"
"github.com/xvzc/SpoofDPI/doh"
@ -83,11 +83,11 @@ func (conn *Conn) ReadBytes() ([]byte, error) {
ret = append(ret, buf[:n]...)
if n < BUF_SIZE {
break
break
}
}
return ret, nil
return ret, nil
}
func (lConn *Conn) HandleHttp(p packet.HttpPacket) {

View File

@ -11,20 +11,26 @@ import (
type Proxy struct {
port string
addr string
}
func New(port string) *Proxy {
func New(addr string, port string) *Proxy {
return &Proxy{
addr: addr,
port: port,
}
}
func (p *Proxy) TcpAddr() string {
return p.addr + ":" + p.port
}
func (p *Proxy) Port() string {
return p.port
}
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 {
log.Fatal("Error creating listener: ", err)
os.Exit(1)

View File

@ -7,22 +7,24 @@ import (
"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")
dns := flag.String("dns", "8.8.8.8", "DNS server")
debug := flag.Bool("debug", false, "true | false")
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))
purple := pterm.NewLettersFromStringWithStyle("DPI", pterm.NewStyle(pterm.FgLightMagenta))
pterm.DefaultBigText.WithLetters(cyan, purple).Render()
pterm.DefaultBulletList.WithItems([]pterm.BulletListItem{
{Level: 0, Text: "ADDR : " + addr},
{Level: 0, Text: "PORT : " + port},
{Level: 0, Text: "DNS : " + dns},
{Level: 0, Text: "DEBUG : " + fmt.Sprint(debug)},