Author Topic: WsCurl To get Location Details and IP Address.  (Read 6444 times)

Vivek Indripala

  • GuiXT Forum
  • Newbie
  • *
  • Posts: 8
    • View Profile
WsCurl To get Location Details and IP Address.
« on: February 28, 2019, 04:44:48 AM »
Purpose: To get IP Address and Location details using WSCurl.

Pre-Requisites:
1. Specify the URL
2. Load wscurl library  load('wscurl.dll');

Liquid UI Script:
/////////////////////////////// SAPLSMTR_NAVIGATION.E0100.sjs ///////////////////////////

load('wscurl.dll');

//Function to check if the string value is blank
function isBlank(jvar) {
   if(jvar==void 0 || jvar=="" || jvar==null) {
      return true;
    }
   else {
      return false;
    }
}


var city;
function getLocationdetails(){

   var wsCurl = new Curl();
   var completeURL = "https://api.ipify.org/?format=text";
   wsCurl.setopt(Curl.CURLOPT_URL,completeURL);
   var response = wsCurl.exec();      
   
   var url = "http://api.ipinfodb.com/v3/ip-city/?key=87a58495dd687d6a0ca9bfadda301bf44fc2697afeb0220d4a6bffff74f18623&ip=";
   
   
   var baseurl = url + response;
   wsCurl.setopt(Curl.CURLOPT_URL,baseurl);
   var JSON_Data = wsCurl.exec();
   var JSON_Data = JSON_Data.toString().split(";");   
   var ipaddress = JSON_Data[1];
   var country = JSON_Data[4];
   var state = JSON_Data[5];
   city = JSON_Data[6];
   set("V[ip_address]",response);
   set("V[city_name]",city);
   set("V[state_name]",state);
   set("V[country_name]",country);
   wsCurl.close();
   wsCurl= NULL;
}


function showOnMaps()
{
   view([5,10],[30,200], "http://maps.google.com/?q="+city,{ "floating":true});   
}

//User Interface
clearscreen();
pushbutton([10,10], "Get Location Details",{ "process":getLocationdetails});
pushbutton([12,10], "Show on Maps",{ "process":showOnMaps});

inputfield( [1,0], "IP_address", [1,16],{ "name":"ip_address", "size":15, "readonly":true});
inputfield( [3,0], "City", [3,16],{ "name":"city_name", "size":15, "readonly":true});
inputfield( [5,0], "state", [5,16],{ "name":"state_name", "size":15, "readonly":true});
inputfield( [7,0], "country", [7,16],{ "name":"country_name", "size":15, "readonly":true});
 
see the attachments for further reference.