mirror of
https://github.com/xvzc/SpoofDPI.git
synced 2025-01-04 13:24:46 +00:00
change src address strategy
This commit is contained in:
parent
117e053751
commit
b8f614d808
@ -11,13 +11,13 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
src := flag.String("src", "127.0.0.1:8080", "source-ip:source-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()
|
||||||
|
|
||||||
err := config.InitConfig(*src, *dns, *debug)
|
err := config.InitConfig(*port, *dns, *debug)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,12 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"log"
|
|
||||||
"strings"
|
|
||||||
"sync"
|
"sync"
|
||||||
"runtime"
|
"runtime"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
SrcIp string
|
Port string
|
||||||
SrcPort string
|
|
||||||
DNS string
|
DNS string
|
||||||
OS string
|
OS string
|
||||||
Debug bool
|
Debug bool
|
||||||
@ -20,31 +16,13 @@ var config *Config
|
|||||||
var once sync.Once
|
var once sync.Once
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
func tokenizeAddress(srcAddress string) (string, string, error) {
|
func InitConfig(port string, dns string, debug bool) error {
|
||||||
tokens := strings.Split(srcAddress, ":")
|
|
||||||
if len(tokens) < 2 {
|
|
||||||
return "", "", errors.New("Error while parsing source address: invalid format.")
|
|
||||||
}
|
|
||||||
|
|
||||||
ip := tokens[0]
|
|
||||||
port := tokens[1]
|
|
||||||
|
|
||||||
return ip, port, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func InitConfig(srcAddress string, dns string, debug bool) error {
|
|
||||||
err = nil
|
err = nil
|
||||||
|
|
||||||
once.Do(func() {
|
once.Do(func() {
|
||||||
ip, port, err := tokenizeAddress(srcAddress)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
config = &Config{
|
config = &Config{
|
||||||
SrcIp : ip,
|
Port : port,
|
||||||
SrcPort : port,
|
|
||||||
DNS : dns,
|
DNS : dns,
|
||||||
OS : runtime.GOOS,
|
OS : runtime.GOOS,
|
||||||
Debug : debug,
|
Debug : debug,
|
||||||
|
@ -16,12 +16,12 @@ func SetOsProxy() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = exec.Command("sh", "-c", "networksetup -setwebproxy " + strings.TrimSpace(string(network)) + " " + GetConfig().SrcIp + " " + GetConfig().SrcPort).Output()
|
_, err = exec.Command("sh", "-c", "networksetup -setwebproxy " + strings.TrimSpace(string(network)) + " 127.0.0.1 " + GetConfig().Port).Output()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = exec.Command("sh", "-c", "networksetup -setsecurewebproxy " + strings.TrimSpace(string(network)) + " " + GetConfig().SrcIp + " " + GetConfig().SrcPort).Output()
|
_, err = exec.Command("sh", "-c", "networksetup -setsecurewebproxy " + strings.TrimSpace(string(network)) + " 127.0.0.1 " + GetConfig().Port).Output()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func Start() {
|
func Start() {
|
||||||
listener, err := net.Listen("tcp", ":" + config.GetConfig().SrcPort)
|
listener, err := net.Listen("tcp", ":" + config.GetConfig().Port)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("Error creating listener: ", err)
|
log.Fatal("Error creating listener: ", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
@ -12,8 +12,7 @@ func PrintWelcome() {
|
|||||||
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: "SOURCE IP : " + config.GetConfig().SrcIp},
|
{Level: 0, Text: "PORT : " + config.GetConfig().Port},
|
||||||
{Level: 0, Text: "SOURCE PORT : " + config.GetConfig().SrcPort},
|
|
||||||
{Level: 0, Text: "DNS : " + config.GetConfig().DNS},
|
{Level: 0, Text: "DNS : " + config.GetConfig().DNS},
|
||||||
}).Render()
|
}).Render()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user