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!