This commit is contained in:
Cyberes 2024-04-11 17:45:14 -06:00
parent 3121face9d
commit adf11183cc
4 changed files with 42 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
dist/
canihazip

16
build.sh Executable file
View File

@ -0,0 +1,16 @@
#!/bin/bash
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
OUTPUTFILE="dist/canihazip"
mkdir -p "$SCRIPT_DIR/dist"
rm "$SCRIPT_DIR"/dist/canihazip &> /dev/null
go mod tidy
go build -v -trimpath -ldflags "-s -w" -o "$OUTPUTFILE"
if [ $? -eq 0 ]; then
chmod +x "$OUTPUTFILE"
echo "Build Succeeded -> $OUTPUTFILE"
fi

21
canihazip.go Normal file
View File

@ -0,0 +1,21 @@
package main
import (
"fmt"
"net"
"net/http"
)
func getMyIP(w http.ResponseWriter, r *http.Request) {
host, _, _ := net.SplitHostPort(r.RemoteAddr)
fmt.Fprint(w, host)
fmt.Printf("Received request from %s\n", host)
}
func main() {
fmt.Println("Server running on 0.0.0.0:5000")
http.HandleFunc("/", getMyIP)
if err := http.ListenAndServe("0.0.0.0:5000", nil); err != nil {
panic(err)
}
}

3
go.mod Normal file
View File

@ -0,0 +1,3 @@
module canihazip
go 1.22.1