Get WAN IP Address

For those of you communicating over the Internet, you may sometimes need to know the “real-world” (WAN) IP address of the PAC running your strategy.

I’ve posted a few other examples of grabbing info off the Internet in various posts (like this one), but just getting this one four-byte piece of IP Address info can essentially be done with one call to the PAC Control HttpGet command. Just make sure your PAC has the DNS and Gateway IP addresses configured on it.

See attached chart which you can import into your 9.1 PAC Control Basic or better strategy with sample code in both regular (action) blocks or OptoScript.

In case you don’t need all that or have a different version of PAC Control, here’s a little snippet of OptoScript code:

// Initialize the tables which will return data from the server
MoveToStrTableElements("", 0, -1, stHttpResponseHeader);
MoveToStrTableElements("", 0, -1, stHttpResponseBody);
MoveToStrTableElements("", 0, -1, stHttpGetHeader);

nSendStatus = [B]HttpGet[/B](
  stHttpResponseBody,      // Return body data dest string table
  stHttpResponseHeader,       // Return header data dest string table
  stHttpGetHeader,  // Source body data string table
  0,                  // 0 for non-secure, <> 0 for SSL
  "/",             // URI
  nHttpStatus,        // Status returned by HTTP server
  80,              // Port to which you want to connect
  "" );  // Address, (numeric or, etc)
//  "" );  // this similar website requires more parsing on what's returned  

if ( (nSendStatus == 0) and (nHttpStatus == 200)) then // odds are good the command worked if we get these values back
  sIP_as_string = stHttpResponseBody[0];

  // at this point, sTemp should include only the IP address in this form: A.B.C.D
  nIP_Integer = IpAddressStringToInt32(sIP_as_string);


Happy web surfing from your PAC!