Пример #1
0
func get_dialer(cfg *Config) (dialer sutils.Dialer, ndialer *msocks.Dialer, err error) {
	err = dns.LoadConfig("resolv.conf")
	if err != nil {
		err = dns.LoadConfig("/etc/goproxy/resolv.conf")
		if err != nil {
			return
		}
	}

	dialer = sutils.DefaultTcpDialer

	dialer, err = cryptconn.NewDialer(dialer, cfg.Cipher, cfg.Keyfile)
	if err != nil {
		return
	}

	ndialer, err = msocks.NewDialer(
		dialer, cfg.Server, cfg.Username, cfg.Password)
	if err != nil {
		return
	}
	dialer = ndialer

	if cfg.Blackfile != "" {
		dialer, err = ipfilter.NewFilteredDialer(
			dialer, sutils.DefaultTcpDialer, cfg.Blackfile)
		if err != nil {
			return
		}
	}

	return
}
Пример #2
0
func run_httproxy(cfg *Config) (err error) {
	var dialer sutils.Dialer

	dialer, err = cryptconn.NewDialer(sutils.DefaultTcpDialer, cfg.Cipher, cfg.Key)
	if err != nil {
		return
	}

	dialer, err = msocks.NewDialer(dialer, cfg.Server, cfg.Username, cfg.Password)
	if err != nil {
		return
	}
	ndialer := dialer.(*msocks.Dialer)

	if cfg.MinSess != 0 {
		ndialer.SessionPool.MinSess = cfg.MinSess
	}
	if cfg.MaxConn != 0 {
		ndialer.SessionPool.MaxConn = cfg.MaxConn
	}

	if cfg.DnsNet == TypeInternal {
		sutils.DefaultLookuper = ndialer
	}
	if cfg.AdminIface != "" {
		mux := http.NewServeMux()
		NewMsocksManager(ndialer.SessionPool).Register(mux)
		go httpserver(cfg.AdminIface, mux)
	}

	if cfg.Blackfile != "" {
		fdialer := ipfilter.NewFilteredDialer(dialer)
		err = fdialer.LoadFilter(sutils.DefaultTcpDialer, cfg.Blackfile)
		if err != nil {
			log.Error("%s", err.Error())
			return
		}
		dialer = fdialer
	}

	for _, pm := range cfg.Portmaps {
		go CreatePortmap(pm, dialer)
	}

	return http.ListenAndServe(cfg.Listen, NewProxy(dialer))
}
Пример #3
0
func main() {
	if len(flag.Args()) < 2 {
		logger.Err("args not enough")
		return
	}
	serveraddr := flag.Args()[0]

	blacklist, err := ipfilter.ReadIPListFile("routes.list.gz")
	if err != nil {
		logger.Err(err)
		return
	}

	var dialer sutils.Dialer
	dialer = sutils.DefaultTcpDialer
	if len(keyfile) > 0 {
		dialer, err = cryptconn.NewDialer(dialer, cipher, keyfile)
		if err != nil {
			logger.Err("crypto not work, cipher or keyfile wrong.")
			return
		}
	} else {
		logger.Warning("no vaild keyfile.")
	}

	ndialer, err := msocks.NewDialer(dialer, serveraddr, username, password)
	if err != nil {
		return
	}

	for _, hostname := range flag.Args()[1:] {
		addrs, err := ndialer.LookupIP(hostname)
		if err != nil {
			logger.Err(err)
			return
		}
		fmt.Println(hostname)
		for _, addr := range addrs {
			fmt.Printf("\t%s\t%t\n", addr, blacklist.Contain(addr))
		}

	}
	return
}