Get IP Address of the User using Apex #inSalesforce
<apex:page controller="IPAddressController">
Login IP Address is {!IPAddress}
</apex:page>
Login IP Address is {!IPAddress}
</apex:page>
Class:
public class IPAddressController{
public string IPAddress {get;set;}
public IPAddressController() {
IPAddress = ApexPages.currentPage().getHeaders().get('True-Client-IP');
if (String.isBlank(IPAddress)) {
IPAddress = ApexPages.currentPage().getHeaders().get('X-Salesforce-SIP');
}
if (String.isBlank(IPAddress)) {
IPAddress = ApexPages.currentPage().getHeaders().get('X-Forwarded-For');
}
}
}
public string IPAddress {get;set;}
public IPAddressController() {
IPAddress = ApexPages.currentPage().getHeaders().get('True-Client-IP');
if (String.isBlank(IPAddress)) {
IPAddress = ApexPages.currentPage().getHeaders().get('X-Salesforce-SIP');
}
if (String.isBlank(IPAddress)) {
IPAddress = ApexPages.currentPage().getHeaders().get('X-Forwarded-For');
}
}
}
Comments
Post a Comment