Author Topic: WSCurl Get IP Address  (Read 5007 times)

Benjamin Dasari

  • GuiXT Forum
  • Newbie
  • *
  • Posts: 95
    • View Profile
WSCurl Get IP Address
« on: September 21, 2016, 03:46:14 PM »
Purpose:
Retrieve the public IP Address using WSCurl.

Liquid UI Code:

// SAPLSMTR_NAVIGATION.E0100.sjs
load('wscurl');

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

// Function to retrieve IP address using WSCURL
function getIPAddress(){
   var wsCurl = new Curl();
      
   /* Build the URL to make a call*/
   var completeURL = "http://www.howtofindmyipaddress.com/";
   
   /* This is the URL for your translation request. Note this use is for
    * calls made to Google Translate which returns us the JSON object in string*/

    wsCurl.setopt(Curl.CURLOPT_URL, completeURL);
   
   /* Final step is to call execute to dispatch email. You can check the return
    * code to avoid errata string which can be found from "wsCurl.error"
    * return value 0 means success*/

   var response = wsCurl.exec();
   var error = wsCurl.error;
   ipaddrline = response.substring(1670,1700);
   
   if(!isBlank(ipaddrline)){
      if(error == 0){
         posStart = ipaddrline.lastIndexOf(">") + 1;
         posEnd = ipaddrline.lastIndexOf("\/") - 1;
         ipaddress = ipaddrline.substring(posStart,posEnd);
         if(isBlank(ipaddress)){
            message('E: Could not find IP address, change URL');
         } else{
            set('V[z_ipaddress]','&V[ipaddress]');
         }   
      }   
   } else{
      message('E: Could not find IP address, change URL');
   }
   
   /* Close the http connection for the URL fetch*/
   wsCurl.close();
   
   /* Remove any reference for Garbage Collection*/
   wsCurl= NULL;
}

// User Interface
clearscreen();
pushbutton([TOOLBAR], 'Get IP Address', '?',{"process":getIPAddress});
inputfield([1,0], "IP Address", [1,16], {"size":15, "name":"z_ipaddress", "readonly":true});   


See attachments for code samples!
« Last Edit: September 22, 2016, 12:32:41 PM by Benjamin Dasari »