# Method getIpAddress not returning what expected

**URL:** <https://forum.inductiveautomation.com/t/method-getipaddress-not-returning-what-expected/96599>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [September 30, 2024, 7:35am UTC](https://forum.inductiveautomation.com/t/method-getipaddress-not-returning-what-expected/96599 "2024-09-30T07:35:04Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tiziano\_F](https://avatars.discourse-cdn.com/v4/letter/t/f6c823/32.png) [@Tiziano\_F](https://forum.inductiveautomation.com/u/Tiziano_F)\
**Post date:** [September 30, 2024, 7:35am UTC](https://forum.inductiveautomation.com/t/method-getipaddress-not-returning-what-expected/96599/1 "2024-09-30T07:35:04Z")

</div>

Hi,  
I'm trying to get the IP address of the client machine.  
I found this documentation: [system.net.getIpAddress | Ignition User Manual](https://www.docs.inductiveautomation.com/docs/8.1/appendix/scripting-functions/system-net/system-net-getIpAddress)

And I understood the difference between gateway scope and client scope, from this usefull doc: [Scripting in Ignition | Ignition User Manual](https://www.docs.inductiveautomation.com/docs/7.9/scripting/scripting-in-ignition#script-scope)

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():

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/c/3/c3a43fe90b6d75cbdd814061c57416bfec0d8675.png)

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:

```python
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!

---

<div class="post-metadata">

**Author:** ![Nathan\_Moore](https://avatars.discourse-cdn.com/v4/letter/n/d78d45/32.png) [@Nathan\_Moore](https://forum.inductiveautomation.com/u/Nathan_Moore)\
**Post date:** [September 30, 2024, 7:40am UTC](https://forum.inductiveautomation.com/t/method-getipaddress-not-returning-what-expected/96599/2 "2024-09-30T07:40:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Nathan\_Moore](https://avatars.discourse-cdn.com/v4/letter/n/d78d45/32.png) [@Nathan\_Moore](https://forum.inductiveautomation.com/u/Nathan_Moore)\
**Post date:** [September 30, 2024, 7:46am UTC](https://forum.inductiveautomation.com/t/method-getipaddress-not-returning-what-expected/96599/3 "2024-09-30T07:46:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Tiziano\_F](https://avatars.discourse-cdn.com/v4/letter/t/f6c823/32.png) [@Tiziano\_F](https://forum.inductiveautomation.com/u/Tiziano_F)\
**Post date:** [September 30, 2024, 7:58am UTC](https://forum.inductiveautomation.com/t/method-getipaddress-not-returning-what-expected/96599/4 "2024-09-30T07:58:10Z")

</div>

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:

> **[Scripting in Ignition | Ignition User Manual](https://www.docs.inductiveautomation.com/docs/8.1/platform/scripting/scripting-in-ignition#script-scope)**
>
> Where Is Scripting Used?

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.

---

<div class="post-metadata">

**Author:** ![Tiziano\_F](https://avatars.discourse-cdn.com/v4/letter/t/f6c823/32.png) [@Tiziano\_F](https://forum.inductiveautomation.com/u/Tiziano_F)\
**Post date:** [September 30, 2024, 7:58am UTC](https://forum.inductiveautomation.com/t/method-getipaddress-not-returning-what-expected/96599/5 "2024-09-30T07:58:53Z")

</div>

Nevermind, i found the solution: [Session Properties | Ignition User Manual](https://www.docs.inductiveautomation.com/docs/8.1/ignition-modules/perspective/perspective-sessions/session-properties#restrictions-from-system-properties)

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

thanks Nathan for helping me think!

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [September 30, 2024, 8:37am UTC](https://forum.inductiveautomation.com/t/method-getipaddress-not-returning-what-expected/96599/6 "2024-09-30T08:37:51Z")

</div>

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

> **[Web Server Settings | Ignition User Manual](https://www.docs.inductiveautomation.com/docs/8.1/platform/gateway/config/web-server-settings)**
>
> The Web Server page is for configuring the HTTP and HTTPS ports, enabling SSL/TLS, redirecting traffic through a known address, and specifying whether or not all HTTP traffic should be forcefully redirecting to HTTPS.

See Resolve Client Hostnames

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [September 30, 2024, 12:40pm UTC](https://forum.inductiveautomation.com/t/method-getipaddress-not-returning-what-expected/96599/7 "2024-09-30T12:40:41Z")

</div>

> [@Tiziano\_F](#):
>
> But it says that there is still difference between the two.

That's because Vision still exists.
