Vivek Mohan
Vivek Mohan

Reputation: 8356

How to identify IP address of requesting client?

How does a server actually identify the requesting client address (IP), and send a response? Is it possible to get the IP address of requesting client in GAE?

Upvotes: 7

Views: 2404

Answers (2)

Peter Knego
Peter Knego

Reputation: 80340

In a Java servlet you could use request.getRemoteAddr():

public void doGet(HttpServletRequest req, HttpServletResponse resp) {
    String ipAddress = req.getRemoteAddr(); 
}

Upvotes: 10

ceving
ceving

Reputation: 23824

If you are using Appengine with Go, the Request object contains the address in the string field RemoteAddr:

import (
    "fmt"
    "net/http"
)

func init() {
    http.HandleFunc("/", handler)
}

func handler(w http.ResponseWriter, r *http.Request) {
    fmt.Fprint(w, r.RemoteAddr)
}

Upvotes: 2

Related Questions