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;}

    //Constructor
    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}

</apex:page>

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

and here it is..!!!!


HAPPY CODING...!!!

13 comments:

  1. this gives salesforce Ip address

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

    how to get that

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

    ReplyDelete
  3. Are you using Standard controller on the page ?

    ReplyDelete
  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. https://192-168-i-i.com

    ReplyDelete

  5. 192.168.1.254

    192.168.l.254

    192.168.1.1

    192.168.o.1

    192.168.l0.1

    192.168.l.l

    192.168.o.1

    is a Private IP address and most powerful universal IP addresses, this is used in the Linksys router.

    ReplyDelete
  6. 192.168.ll
    192.168.l.254

    192.168.o.1

    http//192.168.l.254

    192.168 l0 1
    This IP address is used by the routers like TP-Link, Netgear, D-Link uses it as the default IP address.

    ReplyDelete

  7. Routers are the most important devices that are required to get the internet connectivity. There are many brands and router models around the globe. Most people use multiple brand routers, they don't know how to configure them for the perfect usage. Here at
    192.168.0.1 we have all the manuals for configuring the router login pages.

    ReplyDelete
  8. A round of applause for your mind blowing article. Much thanks to you. Fantastic.

    ReplyDelete

  9. This configuration can also be used for devices like Router, Modem etc. and they are all having the initial IP address

    192.168.10.1

    192.168.0.1

    ReplyDelete