diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b883f1f --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.exe diff --git a/README.md b/README.md new file mode 100644 index 0000000..f2dc67c --- /dev/null +++ b/README.md @@ -0,0 +1,10 @@ +# A simple file share program + +Just like `python -m SimpleHTTPServer`, it opens a simple web server, you can get files from another computer of a phone. + + +``` +$ ./fileshare.exe +Open your browser to the address below: +http://192.168.200.124:8080 +...QRCODE HERE... \ No newline at end of file diff --git a/fileshare.go b/fileshare.go new file mode 100644 index 0000000..6dfac23 --- /dev/null +++ b/fileshare.go @@ -0,0 +1,36 @@ +package main + +import ( + "flag" + "fmt" + "github.com/Baozisoftware/qrcode-terminal-go" + "log" + "net" + "net/http" +) + +func main() { + port := flag.Int("port", 8080, "port number") + + flag.Parse() + + addrs, err := net.InterfaceAddrs() + if err != nil { + panic(err) + } + + obj := qrcodeTerminal.New2(qrcodeTerminal.ConsoleColors.BrightBlue, qrcodeTerminal.ConsoleColors.BrightGreen, qrcodeTerminal.QRCodeRecoveryLevels.Medium) + fmt.Println("Open your browser to the address below, or you can scan the qrcode from your phone.") + for _, addr := range addrs { + if ipnet, ok := addr.(*net.IPNet); ok && ipnet.IP.IsGlobalUnicast() && ipnet.IP.To4() != nil { + url := fmt.Sprintf("http://%s:%d", ipnet.IP.String(), *port) + fmt.Println(url) + + obj.Get([]byte(url)).Print() + fmt.Println() + } + } + + http.Handle("/", http.FileServer(http.Dir("."))) + log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", *port), nil)) +}