How to get IPAddress in Magento 2

Here is a simple way to get IP Address in Magento 2

protected function getIpAddress()
    {
        $om = \Magento\Framework\App\ObjectManager::getInstance();
        $obj = $om->get('Magento\Framework\HTTP\PhpEnvironment\RemoteAddress');
        $ip =  $obj->getRemoteAddress();
        return $ip;
    }
Back to Top