Get Remote address in magento 2 by below code snippet,
<?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,
echo $this->getRemoteAddress();