How can you get a user's IP in PlayFramework2 ?

前端 未结 2 1622
盖世英雄少女心
盖世英雄少女心 2021-01-13 22:57

For security reasons, sometimes it is needed to block users by IP. In my case, I would like to manage the IP blacklist in a (SQL) database. I guess I can handle the filter p

2条回答
  •  北荒
    北荒 (楼主)
    2021-01-13 23:42

    It's now possible with Play 2.0.2+ : RequestHeader.remoteAddress()

    Java :

    String ip = request().remoteAddress();
    

    Scala :

    Action { request =>
        val ip = request.remoteAddress()
    }
    

提交回复
热议问题