function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
richardvrichardv 

IP Address Lookup

How do you lookup the IP Address of the current user from Apex/VisualForce?
Best Answer chosen by Admin (Salesforce Developers) 
richardvrichardv
Thanks TehNrd - its system.debug(ApexPages.CurrentPage().getHeaders().get('x-Salesforce-SIP'));

All Answers

TehNrdTehNrd

It's one of these but I can't recall specifically. I think it also depends on if the user is accessing the VF page through logging in vs accessing a public VF page (Sites). You'll have to experiment.

system.debug(ApexPages.CurrentPage().getHeaders().get('x-original-remote-addr'));
system.debug(ApexPages.CurrentPage().getHeaders().get('x-original-remote-host'));
system.debug(ApexPages.CurrentPage().getHeaders().get('x-Salesforce-SIP'));

 

Edit: FYI these only work within the context of a VF page. I'm pretty sure they don't work in a trigger/future etc.
Message Edited by TehNrd on 02-25-2009 09:08 AM
richardvrichardv
Thanks TehNrd - its system.debug(ApexPages.CurrentPage().getHeaders().get('x-Salesforce-SIP'));
This was selected as the best answer
Srinivasa Rao Latchu 3Srinivasa Rao Latchu 3
How can I fetch ip address in apex class controlling lightning component.?