I use grpc-java and get the metadata by ServerInterceptor, but i get below information without client ip address, the authority is server ip, how can i get the client ip?Thanks.
Metadata({:scheme=[http], :method=[POST], :path=[/test/test1], :authority=[192.168.199.9:50051], grpc-encoding=[identity], grpc-accept-encoding=[identity,deflate,gzip], te=[trailers], content-type=[application/grpc], user-agent=[grpc-objc/0.13.0 grpc-c/0.13.0 (ios)]})
Client IP is not provided in Metadata. But you can call ServerCall.attributes() and get the Grpc.TRANSPORT_ATTR_REMOTE_ADDR.
Please note that the API is unstable and may change.
In latest (1.2.0) gRPC use io.grpc.Grpc.TRANSPORT_ATTR_REMOTE_ADDR
attribute in interceptor to get remote address.
if in python grpc, you will get client ip address and port using context.peer()
.
def your_method(self, request, context):
...
context.peer() # return 'ipv4:49.123.106.100:44420'
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With