mirror of
https://github.com/m1k1o/neko.git
synced 2025-07-30 15:00:26 +02:00
initial commit - from neko open source repository..
This commit is contained in:
commit
56de805f54
66 changed files with 5498 additions and 0 deletions
35
internal/utils/ip.go
Normal file
35
internal/utils/ip.go
Normal file
|
@ -0,0 +1,35 @@
|
|||
package utils
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// dig @resolver1.opendns.com ANY myip.opendns.com +short -4
|
||||
|
||||
func GetIP() (string, error) {
|
||||
rsp, err := http.Get("http://checkip.amazonaws.com")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer rsp.Body.Close()
|
||||
|
||||
buf, err := ioutil.ReadAll(rsp.Body)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return string(bytes.TrimSpace(buf)), nil
|
||||
}
|
||||
|
||||
func ReadUserIP(r *http.Request) string {
|
||||
IPAddress := r.Header.Get("X-Real-Ip")
|
||||
if IPAddress == "" {
|
||||
IPAddress = r.Header.Get("X-Forwarded-For")
|
||||
}
|
||||
if IPAddress == "" {
|
||||
IPAddress = r.RemoteAddr
|
||||
}
|
||||
return IPAddress
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue