|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- package aes
-
- import (
- "applet/app/cfg"
- "applet/app/md"
- "applet/app/utils"
- "code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit"
- "fmt"
- "net"
- "net/http"
- "strings"
- )
-
- func GetIpAddress(request *http.Request, masterId, pvd string) {
- //geoIp2db, _ := geoip2db.NewGeoipDbByStatik()
- //defer geoIp2db.Close()
- ip := GetRemoteClientIp(request)
- if ip != "" {
- //record, _ := geoIp2db.City(net.ParseIP(ip))
- //if record.Country.Names != nil && record.Subdivisions != nil && record.City.Names != nil {
-
- // aesData := fmt.Sprintf(
- // `{"country":"%s","province":"%s","city":"%s","ip":"%s", "master_id":"%s", "url":"%s", "pvd":"%s"}`,
- // record.Country.Names["zh-CN"], record.Subdivisions[0].Names["zh-CN"], record.City.Names["zh-CN"], ip, masterId, request.Host, pvd)
-
- aesData := fmt.Sprintf(
- `{"ip":"%s", "master_id":"%s", "url":"%s", "pvd":"%s"}`,
- ip, masterId, request.Host, pvd)
- fmt.Println(aesData)
- if cfg.Prd {
- //TODO::正式环境,推入rabbitMq
- ch, _ := rabbit.Cfg.Pool.GetChannel()
- defer ch.Release()
- ch.Publish(md.UserVisitIpAddress, aesData, "")
- }
- //}
- }
-
- return
- }
-
- //func GetIp() (ip string) {
- // conn, _ := net.Dial("udp", "google.com:80")
- // if err != nil {
- // return
- // }
- // defer conn.Close()
- // ip = strings.Split(conn.LocalAddr().String(), ":")[0]
- // return
- //}
-
- // GetRemoteClientIp 获取远程客户端IP
- func GetRemoteClientIp(r *http.Request) string {
- remoteIp := r.RemoteAddr
- if ip := r.Header.Get("X-Real-IP"); ip != "" {
- if strings.Contains(ip, "172.20") {
- ips := strings.Split(r.Header.Get("X-Forwarded-For"), ",")
- if len(ips) == 2 {
- remoteIp = ips[0]
- }
- } else {
- remoteIp = ip
- }
- } else if ip = r.Header.Get("X-Forwarded-For"); ip != "" {
- remoteIp = ip
- } else {
- remoteIp, _, _ = net.SplitHostPort(remoteIp)
- //remoteIp = ""
- }
-
- //本地ip
- if remoteIp == "127.0.0.1" || remoteIp == "::1" {
- remoteIp = "221.4.210.1651"
- }
-
- if r.Host == "h5.99813608.zhiyingos.com" {
- utils.FilePutContents("GetRemoteClientIp", utils.SerializeStr(map[string]interface{}{
- "header": r.Header,
- "remoteIp": remoteIp,
- }))
- }
- fmt.Println(">>>>>>>>>>>>>>>>>>>>GetRemoteClientIp<<<<<<<<<<<<<<<<<<", remoteIp)
- return remoteIp
- }
|