-2

I have an beego application where I need to get the client side IP address and send it to server in same format or string format.

How can I get the IP address of the client so that I can send it to server and display on server side.

    l_channel_ip := "10.11.0.123"

Here I am hard coding the value now. But I don't want it to be hard coded like this. Instead the clients IP should be stored in l_channel_ip.

Dave C
  • 7,729
  • 4
  • 49
  • 65
Vijay Kumar
  • 597
  • 2
  • 8
  • 27

2 Answers2

1

This code provide IP address for you

s := this.Ctx.Input.IP()

Use beego internal istead custom parsing.

Vitold S.
  • 402
  • 4
  • 13
0

This code stores the ip in "l_channel_ip" variable

func (this *baseController) getClientIp() string {
s := strings.Split(this.Ctx.Request.RemoteAddr, ":")
return s[0]
}

l_channel_ip := getClientIp()
Sailesh Kotha
  • 1,939
  • 3
  • 20
  • 27