+ Start a Discussion
SirTravSirTrav 

Get the IP address of the person accessing the visualforce page

I have a visualforce page and want to track the IP address of the user who accesses it.  ApexPages.currentPage().getHeaders().get('True-Client-IP'); and ApexPages.currentPage().getHeaders().get('X-Salesforce-SIP'); but the X-Salesforce-SIP only returns the Salesforce IP not the users public IP.  the True-Client-IP comes back as null.  I had this setup once using Javascript but I don't remember the code and lost where I had it saved.  Can anyone help with a way to get the IP address of the person accessing the visualforce page?

KodiKodi

Hi,
if you want this type of output means use this code,

public string getipadd()
{
host= ApexPages.currentPage().getHeaders().get('Host');
referer=ApexPages.currentPage().getHeaders().gete('Referer');
useragent=ApexPages.currentPage().getHeaders().get('User-Agent');
chipersuite=ApexPages.currentPage().getHeaders().get('Chipersuite');
forward=ApexPages.currentPage().getHeaders().get('X-Salesforce-Forwarded-To');
salesforceip= ApexPages.currentPage().getHeaders().get('X-Salesforce-SIP');
return null;
}

Outputs:
1. kodishdemo-dev-ed--c.ap1.visual.force.com
2. salesforce
3. RD4-MC5 TLDv1 128-bits salesforce
4. ap1.salesforce.com
5. 192.73.246.115

SirTravSirTrav
The problem with all of that is that none of it will get me the users ip address of the end user.  ApexPages.currentPage().getHeaders().get('X-Salesforce-SIP');  returns the salesforce ip address.