Skip to content

Commit

Permalink
style: 伪装ip无用,删除相关代码
Browse files Browse the repository at this point in the history
  • Loading branch information
bincooo authored and bincooo committed Oct 14, 2023
1 parent 4f6b435 commit 58d0490
Showing 1 changed file with 0 additions and 69 deletions.
69 changes: 0 additions & 69 deletions chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/google/uuid"
"github.com/sirupsen/logrus"
"io"
"math/rand"
"net/http"
"net/url"
"strconv"
Expand Down Expand Up @@ -516,7 +515,6 @@ func (c *Chat) initHeader() http.Header {
h.Set(k, v)
}
}
h.Set("X-Forwarded-For", randomIp())
return h
}

Expand All @@ -532,70 +530,3 @@ func deleteItem[T any](slice []T, condition func(item T) bool) []T {
}
return slice
}

// 获取随机ip
// https://github.com/Harry-zklcdc/go-proxy-bingai/blob/fb6adba0da2745840bea5ce285097e84ecd085ab/cloudflare/worker.js#L97
func randomIp() string {
r := rand.New(rand.NewSource(time.Now().UnixNano()))
ip2Int := func(ip string) int {
slice := strings.Split(ip, ".")
result := 0
atoi, _ := strconv.Atoi(slice[0])
result += atoi << 24
atoi, _ = strconv.Atoi(slice[1])
result += atoi << 16
atoi, _ = strconv.Atoi(slice[2])
result += atoi << 8
atoi, _ = strconv.Atoi(slice[2])
result += atoi
return result
}

int2Ip := func(num int) (result string) {
result += strconv.Itoa(num>>24&255) + "."
result += strconv.Itoa(num>>16&255) + "."
result += strconv.Itoa(num>>8&255) + "."
result += strconv.Itoa(num & 255)
return
}

randIndex := r.Intn(len(IP_RANGE))
startIPInt := ip2Int(IP_RANGE[randIndex][0])
endIPInt := ip2Int(IP_RANGE[randIndex][1])

newIpInt := r.Intn(endIPInt-startIPInt) + startIPInt
return int2Ip(newIpInt)
}

var IP_RANGE = [][]string{
{"4.150.64.0", "4.150.127.255"}, // Azure Cloud EastUS2 16382
{"4.152.0.0", "4.153.255.255"}, // Azure Cloud EastUS2 131070
{"13.68.0.0", "13.68.127.255"}, // Azure Cloud EastUS2 32766
{"13.104.216.0", "13.104.216.255"}, // Azure EastUS2 256
{"20.1.128.0", "20.1.255.255"}, // Azure Cloud EastUS2 32766
{"20.7.0.0", "20.7.255.255"}, // Azure Cloud EastUS2 65534
{"20.22.0.0", "20.22.255.255"}, // Azure Cloud EastUS2 65534
{"40.84.0.0", "40.84.127.255"}, // Azure Cloud EastUS2 32766
{"40.123.0.0", "40.123.127.255"}, // Azure Cloud EastUS2 32766
{"4.214.0.0", "4.215.255.255"}, // Azure Cloud JapanEast 131070
{"4.241.0.0", "4.241.255.255"}, // Azure Cloud JapanEast 65534
{"40.115.128.0", "40.115.255.255"}, // Azure Cloud JapanEast 32766
{"52.140.192.0", "52.140.255.255"}, // Azure Cloud JapanEast 16382
{"104.41.160.0", "104.41.191.255"}, // Azure Cloud JapanEast 8190
{"138.91.0.0", "138.91.15.255"}, // Azure Cloud JapanEast 4094
{"151.206.65.0", "151.206.79.255"}, // Azure Cloud JapanEast 256
{"191.237.240.0", "191.237.241.255"}, // Azure Cloud JapanEast 512
{"4.208.0.0", "4.209.255.255"}, // Azure Cloud NorthEurope 131070
{"52.169.0.0", "52.169.255.255"}, // Azure Cloud NorthEurope 65534
{"68.219.0.0", "68.219.127.255"}, // Azure Cloud NorthEurope 32766
{"65.52.64.0", "65.52.79.255"}, // Azure Cloud NorthEurope 4094
{"98.71.0.0", "98.71.127.255"}, // Azure Cloud NorthEurope 32766
{"74.234.0.0", "74.234.127.255"}, // Azure Cloud NorthEurope 32766
{"4.151.0.0", "4.151.255.255"}, // Azure Cloud SouthCentralUS 65534
{"13.84.0.0", "13.85.255.255"}, // Azure Cloud SouthCentralUS 131070
{"4.255.128.0", "4.255.255.255"}, // Azure Cloud WestCentralUS 32766
{"13.78.128.0", "13.78.255.255"}, // Azure Cloud WestCentralUS 32766
{"4.175.0.0", "4.175.255.255"}, // Azure Cloud WestEurope 65534
{"13.80.0.0", "13.81.255.255"}, // Azure Cloud WestEurope 131070
{"20.73.0.0", "20.73.255.255"}, // Azure Cloud WestEurope 65534
}

0 comments on commit 58d0490

Please sign in to comment.