Friday, 7 February 2014

Show IP Address on Visualforce Page Salesforce

This is one of the thing, that previously I never thought that it would be help full, but at some point it is.

When you want some where to show the current user's Ip address on page, OR weather you want to restrict a User of a particular IP then you can use this small code snippet with some booming functionality.

Apex Class ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

public class IPAddress {

    //Variable to hold the IP Address value for current logged in user
    public String ipAddress {get; set;}

    public IPAddress() {

        //Map to hold current URL header parameters
        Map<String, String> mapHeaders = ApexPages.currentPage().getHeaders();  

    //Proceed further only and only if map of header parameter have not null value with it
        if(mapHeaders != null) {

            ipAddress = mapHeaders.get('True-Client-IP');
            if(ipAddress == null){
                ipAddress = mapHeaders.get('X-Salesforce-SIP');


VisualForce page ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

<apex:page controller="IPAddress">

<h1> Current Logged In User IP Address ::::: </h1>   {!IpAddress}



and here it is..!!!!



  1. this gives salesforce Ip address

    i want my system ipv4 address to get retrieved...

    how to get that

  2. but it is not working in inline visualforce page , canu tell me the code for getting ip inline visualforce page

  3. Are you using Standard controller on the page ?

  4. You there, this is really good post here. Thanks for taking the time to post such valuable information. Quality content is what always gets the visitors coming.



    router login
    Positive site, where did u come up with the information on this posting?I have read a few of the articles on your website now,