Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
notsobad committed Mar 24, 2019
0 parents commit 4337184
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.exe
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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...
36 changes: 36 additions & 0 deletions fileshare.go
Original file line number Diff line number Diff line change
@@ -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))
}

0 comments on commit 4337184

Please sign in to comment.