代理池,集
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
proxyPool/gomitmproxy.go

85 lines
1.6 KiB

// This example shows a proxy server that uses go-mitm to man-in-the-middle
// HTTPS connections opened with CONNECT requests
9 years ago
package main
import (
"flag"
"log"
9 years ago
"net/http"
"os"
"sync"
9 years ago
"time"
)
const (
Version = "1.1"
9 years ago
)
var (
wg sync.WaitGroup
)
9 years ago
var logFile *os.File
var logger *log.Logger
func main() {
var conf Cfg
9 years ago
conf.Port = flag.String("port", "8080", "Listen port")
conf.Raddr = flag.String("raddr", "", "Remote addr")
conf.Log = flag.String("log", "./error.log", "log file path")
conf.Monitor = flag.Bool("m", false, "monitor mode")
conf.Tls = flag.Bool("tls", false, "tls connect")
9 years ago
flag.Parse()
var err error
logFile, err = os.Create(*conf.Log)
9 years ago
if err != nil {
log.Fatalln("fail to create log file!")
9 years ago
}
logger = log.New(logFile, "[gomitmproxy]", log.LstdFlags|log.Llongfile)
9 years ago
wg.Add(1)
gomitmproxy(&conf)
wg.Wait()
9 years ago
}
func gomitmproxy(conf *Cfg) {
tlsConfig := NewTlsConfig("gomitmproxy-ca-pk.pem", "gomitmproxy-ca-cert.pem", "", "")
9 years ago
handler, err := InitConfig(conf, tlsConfig)
9 years ago
if err != nil {
logger.Fatalf("InitConfig error: %s", err)
9 years ago
}
server := &http.Server{
Addr: ":" + *conf.Port,
Handler: handler,
ReadTimeout: 1 * time.Hour,
WriteTimeout: 1 * time.Hour,
9 years ago
}
go func() {
log.Printf("proxy listening port:%s", *conf.Port)
9 years ago
if *conf.Tls {
log.Println("ListenAndServeTLS")
err = server.ListenAndServeTLS("gomitmproxy-ca-cert.pem", "gomitmproxy-ca-pk.pem")
} else {
log.Println("ListenAndServe")
err = server.ListenAndServe()
9 years ago
}
if err != nil {
logger.Fatalf("Unable to start HTTP proxy: %s", err)
9 years ago
}
wg.Done()
9 years ago
log.Printf("gomitmproxy stop!!!!")
}()
9 years ago
return
}