I am using Crow (C++ server library) and trying to get the client's IP address.
I found this answer, Getting the client IP address: REMOTE_ADDR, HTTP_X_FORWARDED_FOR, what else could be useful?, so I have tried:
CROW_ROUTE(app, "/mine")([](const crow::request& req, crow::response& res)
{
std::string ip_address = req.get_header_value("REMOTE_ADDR");
res.write(req.get_header_value("HTTP_X_FORWARDED_FOR"));
res.write(req.get_header_value("HTTP_CLIENT_IP"));
res.write(req.get_header_value("HTTP_X_FORWARDED"));
res.write(req.get_header_value("HTTP_X_CLUSTER_CLIENT_IP"));
res.write(req.get_header_value("HTTP_FORWARDED_FOR"));
res.write(req.get_header_value("HTTP_FORWARDED"));
for( auto head : req.headers )
{
res.write(head.first);
res.write(" = ");
res.write(head.second);
res.write( "<br/>" );
}
res.end();
});
But all of those header fields are blank. Is there another way to get the IP address or is my browser just not sending the required information?