cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - You can subscribe to a forum, label or individual post and receive email notifications when someone posts a new topic or reply. Learn more! X

How to access current URL or server IP in script

nparikh
2-Guest

How to access current URL or server IP in script

Hello,

We have three Thingworx servers, For development, testing and production hosted with PTC. We have separate configuration Thing to store server specific properties. I don't want to maintain three different Things. But, instead based on URL/IP I want to load properties from Thing. Is there any way to read current server IP/URL ?

8 REPLIES 8

Not out of the box, we have a Custom Thing with a shared ThingShape/ThingTemplate in order to configure this kind of properties. The only thing to get your current IP will be to call an external "WhatsMyIP" service.

Aanjan
9-Granite
(To:nparikh)

Nirav, the CurrentSessionInfo Resource has a service called 'GetCurrentIPAddress' to fetch the IP address.

Hi Aanjan,

Nirav it's asking for Server IP not User IP, anyway GetCurrentIPAddres ( which it's user IP ) almost never works

Carles.

Ah my bad, I didn't read right. The GetCurrentIPAddres service will return the user address, not the platform.

You can use location.host in an Expression widget (and evaluate that) to get the current server address. You can bind the output to any service.

But you can't depend on a user entering on a mashup to get Server configuration...

True, but this would depend on the use case. If Mashups are ultimately going to be used to pass through, this can be stored in a variable and passed on to a service.

Is it possible to write an extension to read server IP and call service from script ? whatismyip is 3rd party, I want to avoid it, if possible.

I suppose yes, it's just Java, just doing a google search: How to get Server IP address in Java

Top Tags