Recommended class to get gateway address

When building a module, what is the recommended class to use in order to get the gateway DNS?

It would be the equivalent of “system.util.getGatewayAddress()”

If I search for “getGatewayAddress” in the Ignition java docs there are many options, or so it seems.

Thanks,

Nick

Gateway address (route) for a network and DNS server address are different things. And both are different from the return value of system.util.getGatewayAddress().

The latter is used from a Vision client to know where to contact the gateway if an out-of-band connection is needed.

For the “default gateway” network route, java doesn’t actually expose it in any standard way. The best you can do is identity the network interface that would be used to hit the default gateway (by connecting a UDP socket to some arbitrary but routable external address).

Java also does not expose any information about DNS, but will look up names for you. See the java.net package.

I am looking to get the equivalent of what is in this tag:

[System]Client/Network/GatewayAddress

Our gateway address, is the address of the site VM and its always the same, only the site number changes.

For parsing through SAML response AD groups and assigning roles, we have AD groups that contain that number and are site specific.

So in order to make the module generalize to all sites, that is why I am looking for how to get the gateway address via java script.

Nick

This gets me what I need, I’m just not sure its the most efficient way (although it does work)

import com.inductiveautomation.factorypmi.application.script.builtin.ClientSystemUtilities;

    public String getGatewayAddress(){
        String gwAddr = ClientSystemUtilities.getGatewayAddress();
        return gwAddr;
    }

Key point is to make sure the compile setting is set to “provided” for this dependency otherwise the module file becomes several hundred megabytes.

Nick

1 Like

Assuming you’re calling this from Vision client scope, you can ‘shortcut’ that system utils call via:

var connection = com.inductiveautomation.ignition.client.gateway_interface.GatewayConnectionManager#getInstance();
var httpUrl = connection.getGatewayAddress();

where httpUrl will be a com.inductiveautomation.ignition.common.gateway.HttpURL you can examine for different information. ClientSystemUtilities does the same thing, but toString()s the result.

@PGriffith we use SSO to control login to all scopes (gateway, designer, vision, and perspective) so we need something which will accommodate all.

I guess what I am using now will not work since the dependency is listed as:

com.inductiveautomation.vision.vision-client

Functionally it's almost like I need a way to read the following tag from anywhere:

[System]Client/Network/GatewayAddress

Thanks,

Nick

I think you’ll have to introduce your own abstraction here. For Vision or the designer, the ‘gateway address’ is, by definition, the address that the local JVM is receiving communications from, so it’s known. Similarly for Perspective, which is what we put into the session property. For general gateway use, you’re going to have a hard time; there’s no communication channel to check. You could check for a specific named NetworkInterface, if you’re able to make guarantees about where your module will be installed.

@PGriffith thanks for the reply.

Is there any class that would allow me to read a tag?

Yes, but if you're planning to read [System]Client/Network/GatewayAddress, that won't do any good. That tag only exists in the client & designer scope, where it will just return the same result as the code I posted further up stream.

For programatically reading a tag, see this thread, except instead of browseAsync you'll be calling readAsync:

@PGriffith because our gateway VM’s always have a certain address format we think we can use the following and pass the return into our function as an additional parameter.

As far as we can tell it will work because we invoke the script from the attribute mapping on the IDP using “runScript” and because it will then run in the gateway context, it will give us the gateway hostname that is not modifiable hence a reliable source of the site number.

system.net.getHostName()

Nick