Get Remote address in magento 2 by below code snippet,
1 2 3 4 5 6 7 8 9 10 | <?php public function __construct( \Magento\Framework\HTTP\PhpEnvironment\RemoteAddress $remoteAddress ) { $this->_remoteAddress = $remoteAddress; } public function getRemoteAddress(){ $remoteAddress = $this->_remoteAddress->getRemoteAddress(); return $remoteAddress; } |
Call function in template file by below way,
1 | echo $this->getRemoteAddress(); |