master
Bel LaPointe 2019-02-09 11:00:02 -07:00
parent 839706b226
commit 81782bb794
1 changed files with 11 additions and 9 deletions

20
main.go
View File

@ -4,7 +4,7 @@ import (
"encoding/binary"
"encoding/csv"
"flag"
"local/logger"
"fmt"
"log"
"net"
"net/http"
@ -31,11 +31,13 @@ func main() {
getIPs()
http.Handle("/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
remoteIP := strings.Split(r.RemoteAddr, ":")[0]
if notUSA(remoteIP) {
logger.Log(remoteIP, "NOT USA")
return
}
/*
remoteIP := strings.Split(r.RemoteAddr, ":")[0]
if notUSA(remoteIP) {
fmt.Println(remoteIP, "NOT USA")
return
}
*/
if r.URL.Scheme == "http" || strings.HasPrefix(r.Host, "http:") {
r.URL.Scheme = "https"
http.Redirect(w, r, r.URL.String(), http.StatusTemporaryRedirect)
@ -67,7 +69,7 @@ func getIPs() []uint64 {
if err != nil {
panic(err)
}
logger.Log("IPV4s")
fmt.Println("IPV4s")
for i := range ipv4all {
if ipv4all[i][2] == "US" || ipv4all[i][2] == "-" {
start, err := strconv.ParseUint(ipv4all[i][0], 10, 64)
@ -92,7 +94,7 @@ func getIPs() []uint64 {
if err != nil {
panic(err)
}
logger.Log("IPV6s")
fmt.Println("IPV6s")
for i := range ipv6all {
if ipv6all[i][2] == "US" {
start, err := strconv.ParseUint(ipv6all[i][0], 10, 64)
@ -118,7 +120,7 @@ func notUSA(ip string) bool {
n := sort.Search(len(ips), func(i int) bool {
return ips[i] > dec
})
logger.Log(ip, dec, ips[0], n, len(ips))
fmt.Println(ip, dec, ips[0], n, len(ips))
return n%2 == 1
}