In perspective this script will be run on the gateway, and so will only return the Ip address of the Gateway Server.
Due to browser security, I would guess it would be impossible to get the IP address of the users PC.
As an aside, why would it matter what IP a user opened a client from? This is exactly the thing that Users and User Roles are made for. If an unauthorized user logs in with invalid credentials then they wouldn’t have access.
Thank you! The thing is sometimes we want to be able to detect the IP address of the user and location they are in and then give them access. For example, a remote user with the IP of 1.2.3.4 cannot log in to the perspective project.
I also tried this script on gateway events too but it did not work.
Returns the IP address of the computer that the script was ran on. When run in the Gateway scope, returns the Gateway IP address. When run in the Client scope, returns the Client IP address.
system.net.getIpAddress() will return the Gateway's IP address.
When you say it didn't work, does that mean you got an error, or it didn't do what you expected?
I believe that Security Zones are the answer to this particular issue. Then rather than granting access based on an IP address, you would grant it based on a security zone.
Something that you hinted at with your suggestion but did not outright say is that those system.security functions in @pkhoshroo’s initially posted scripts are specifically Vision client-scoped functions, and as such will not run in a Perspective session.
As you said, I think a change script on session.props.address (assuming OP is using a recent enough version of Ignition to have access to this property) that evaluates whether the IP address is allowed or not is likely the best bet.
You should create a new security ZONE which “black-lists” the IP address (or white-lists the range of IPs which do not include the bad IP address), and then your project should require that security zone.