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
rajesh k 10rajesh k 10 

URGENT:How to get My system IPv4 Address using apex in salesforce?

How to get My system Address means Control panel->Network Access-->LAN-->IPv4 Address

please help me....
NaveenReddyNaveenReddy
Hi,

 Please try this code.

public static String GetUserIPAddress() {
	string ReturnValue = '';

	ReturnValue = ApexPages.currentPage().getHeaders().get('True-Client-IP');
			
	if (ReturnValue == '') {
		ReturnValue = ApexPages.currentPage().getHeaders().get('X-Salesforce-SIP');
	} // get IP address when no caching (sandbox, dev, secure urls)
			
	system.debug('USER IP ADDRESS: ' + ReturnValue);
		
	return ReturnValue;
		
} // GetUserIPAddress

Also go through below link.

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


Regards,
Naveen
http://www.autorabit.com
Abu Hashim ShaikAbu Hashim Shaik
I've tried the above code, but the IP generated through this code does not match with the IP4 address in my system.
NaveenReddyNaveenReddy
Hi,

 Please check whether your system using dynamic IPs or Static IPs.

User-added image

NaveenReddyNaveenReddy
Try this query

Select SourceIp from LoginIp;
NaveenReddyNaveenReddy
Hi Rajesh,

I have run the below query and getting correct IP Address.Hope this will solve your problem.

User-added image



**Mark it as best answer if it solves your problem.

Naveen

SSE , Salesforce CI expert group

http://www.autorabit.com

Automated deployments , Dataloader , Sandbox back-ups, test automation for Salesforce applications
rajesh k 10rajesh k 10
Hi NaveenReddy,
                                   Using above Query i was getting what is my ip address only not IPv4 address.