Get my IP - from browser Follow
Sometimes the client wants to know his/her IP in the browser. However, the browser has strict permissions in returning data about the current user.
The way to do that is by using an API of AuraPlayer -
http://<host>:<port>/
The API does not require any input field.
Expected response would be as follows:
{
"success": true,
"objectName": "com.auraplayer.model.system.WhoAmI",
"data": {
"clientIp": "<client IP>",
"clientHostname": "<client hostname>"
}
}
This API call would return the IP of the client and the hostname.
NOTICE: this information is useful mostly for internal networks - then the client can get the hostname.
In external networks (such as mobile, or external organizations) the client would get the router's IP instead of the client's IP.
See below the code snippet to:
- get the client IP
- set it in parameters
It is possible to call this code on 'onload', or when performing an action:
$.getJSON("/ServiceManager/Macro/WhoAmI", function(resp){
try{
var clientIP = resp.data.clientIp;
var clientHostName = resp.data.clientHostname;
populateField("IP_FIELD_NAME",clientIP)
populateField("HOSTNAME_FIELD_NAME",clientHostName)
}catch(e){
console.error("Error in getting client's IP")
showConfirmPopup("Get Client IP", "Error in getting the client IP")
}
});
* $.getJSON(...) is a jQuery function for performing HTTP request, it is possible to perform any other funciton.
** function(resp){......} is the callback function to analyze and set theresponse from the HTTP call.
Comments
0 comments
Please sign in to leave a comment.