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
idan ashtamkeridan ashtamker 

Custom Button or Link - Get IP address

Hi. I'm trying to get the current machin name (ip address) of the pc, with the Custom Button or Link, using "execute javascript".
I tried several things, but didn't succeed, Help?
thanks  :)
 
Mahesh DMahesh D
Hi Idan,

ApexPages.currentPage().getHeaders() will let you see:
 
True-Client-IP has the value when the request is coming via the caching integration. 
X-Salesforce-SIP has the value if there is no caching integration (sandbox, developer edition orgs) or via the secure url 

 
Map<String, String> mapHeaders = ApexPages.currentPage().getHeaders();
if(mapHeaders != null){
  ipAddress = mapHeaders.get('True-Client-IP');
  if(ipAddress == null){
    ipAddress = mapHeaders.get('X-Salesforce-SIP');
  }
}

Please go through the below links for more information:

https://developer.salesforce.com/forums/?id=906F00000008wADIAY

https://success.salesforce.com/answers?id=90630000000giq9AAA


Also go through the Idea posted on the same topic and vote for it.

https://success.salesforce.com/ideaView?id=08730000000JJc1


Please do let me know if it helps you.

Regards,
Mahesh
Ravi Dutt SharmaRavi Dutt Sharma
There is a similar question present here (https://developer.salesforce.com/forums/?id=906F000000091DXIAY), please check.
Mahesh DMahesh D
Hi Idan,

Did you get a chance to validate it, please mark it as solved once you satisfy with the response. It will be helpful for others in the future.

Regards,
Mahesh
idan ashtamkeridan ashtamker
Thanks, but eventually I did it in my controller (I'm calling a controller action in the javascript event), and in the controller I'm getting the IP address of the client  :)
Mahesh DMahesh D
Hi Idan,

Please paste the code here so it that it will be helpful to others in the future.

And also mark it as solved.

Regards,
Mahesh