Apex Class:
public class IPAddressController { public string IPAddress {get;set;} public IPAddressController() { IPAddress = ApexPages.currentPage().getHeaders().get('True-Client-IP'); //Get IP address when no caching (sandbox, dev, secure urls) if (String.isBlank(IPAddress)) { IPAddress = ApexPages.currentPage().getHeaders().get('X-Salesforce-SIP'); } if (String.isBlank(IPAddress)) { IPAddress = ApexPages.currentPage().getHeaders().get('X-Forwarded-For'); } } }
Visualforce Page:
<apex:page controller="IPAddressController"> Your Login IP Address : {!IPAddress} </apex:page>