Method getIpAddress not returning what expected

Hi,
I'm trying to get the IP address of the client machine.
I found this documentation: system.net.getIpAddress | Ignition User Manual

And I understood the difference between gateway scope and client scope, from this usefull doc: Scripting in Ignition | Ignition User Manual

From what I understand, when a script is executed from a button that the client pressed (from the operator) it should be classified as a client scope. So theoretically i should get the Ip address 192.168.1.135 (that is fixed for this client machine). However I still get the gateway Ip, that is 192.168.1.115 (also is fixed for the gateway machine).
This is a test button, which his text value is also get for the method getIpAddress():

and this is the code that the button runs on "onActionPerformed", in the logger is still get the gateway ip and not the client ip:

def runAction(self, event):
	import json
	import socket
	logger = system.util.getLogger("myLogger")
	# Leggi il JSON degli IP consentiti dal tag Ignition
	ip_json = json.loads(str(system.tag.readBlocking(["[default]altro/allowedIP"])[0].value))
	
	# Ottieni l'IP del client che esegue lo script
	hostname = socket.gethostname()
	client_ip = socket.gethostbyname(hostname)
	logger.info("my ip: " + str(client_ip) )
	# Controlla se l'IP del client è presente nel json allowedIP
	is_allowed = any(item['ip'] == str(client_ip) for item in ip_json)
	
	if is_allowed:
		logger.info("is ok")
	else:
		logger.info("is not ok")

Where am I wrong? I don't get it!

Thanks for anyone helping!

I believe any script event in perspective takes place on the gateway scope. In Vision it may be client scope.

You could probably use the session property. session.props.address instead.

1 Like

Oh i just discovered that the doc page difference between the gateway and client scope is for 7.9, this the the new version 8.1:

And from what i understand, all the client button will run in the Gateway. But it says that there is still difference between the two.
I'm really confused...

What I also found is this property:
self.session.props.device.identifier

that returns something like this:
d67207a5-bc45-425d-8640-bcc0dbccf00c

But this identifier will always be fixed? because i would need someting that is always fixed for the client machine.

Nevermind, i found the solution: Session Properties | Ignition User Manual

just use this property in the scripts:
self.session.props.host

thanks Nathan for helping me think!

Host could be the hostname if you have reverse DNS set up on the gateway, so if you want the ip address, use address as Nathan mentioned

See Resolve Client Hostnames

1 Like

That's because Vision still exists.

1 Like