Written by

Article Hiroshi Sato · Mar 15, 2023 1m read

How to get client IP or machine name

InterSystems FAQ rubric
 

When connecting to the database using a client-server architecture, for example using language binding, the machine name of the client can be obtained using the following code:

set client=##CLASS(%SYS.ProcessQuery).Open("P"_$j).ClientNodeName

The IP address of the client can be obtained by:

set ip=##CLASS(%SYS.ProcessQuery).Open("P"_$j).ClientIPAddress

* If the server and client are the same, the IP address obtained above will be 127.0.0.1.

Comments

David Hockenbroch · Mar 21, 2023

Where I've used that second option to get an IP address, I've noticed that if the client has more than one IP address, it can return different ones different times, and I'm not sure how it determines which one.

0
Alexey Maslov  Mar 22, 2023 to David Hockenbroch

It seems to be an IP of its first network adapter, probably of virtual one.

0
Alexey Maslov · Mar 22, 2023

Hiroshi,
May I ask you where did it ever work?

Here are the results of quick test in Studio Output window: 

w"*"_$zio_"*"
**
w"*"_$zutil(67,12,$j)_"*"
*MYPC*
w##CLASS(%SYS.ProcessQuery).Open("P"_$j).ClientNodeName ; prefered (documented) way
MYPC
w##CLASS(%SYS.ProcessQuery).Open("P"_$j).ClientIPAddress
10.8.3.37

Alternative program which supports CacheActiveX connection showed the same results, by the way, regardless of server's platformwhether it was UNIX/Linux or Windows.

IRIS for Windows (x86-64) 2021.1 (Build 215U) Wed Jun 9 2021 09:39:22 EDT

while results were similar in all previous Cache/IRIS versions I managed to run.

0
Alexey Maslov  Mar 22, 2023 to Alexey Maslov

I should check docs before any "quick testing": only terminal (TRM:), telnet and file current devices can provide $ZIO with non-empty values. No client/server!

0
Hiroshi Sato  Mar 23, 2023 to Alexey Maslov

Thanks for pointing that out.
Certainly this method does not give us the answers we are currently expecting.
This article was originally posted in Japan quite some time ago, so it certainly would have worked in past versions.
Anyway, I will try to rewrite this article so that it works as expected in the latest version.

0
Alexey Maslov  Mar 24, 2023 to Hiroshi Sato

Hiroshi, take it easy - everybody can make a mistake.
Meanwhile, I'm sure that $ZIO was initially intendent for terminal devices only. Here is the oldest link I was able to find: https://cedocs.intersystems.com/documentation/cache/cache41/olr/olrvzio…
Why not use ##CLASS(%SYS.ProcessQuery) for similar purposes? It's more powerful and better documented than some "mystic" system variables and functions.
Happy writing!

0