fetch ip address of cache installation

Caché

I'm using cache  win10-x64  version 2017.2.1.801

I want to uniquely identify the installation of cache, and from that create a meaningful unique folder names to store files. 

so to generate \192-168-1-100\KEVDEV\testfolder \ and \192-168-1-5\LIVE\testfolder\

so in this case, I could- use the IPaddress and thesecond part of $SYSTEM (cache instance name) - at least this way, I can instantly see where it came from with little risk of overwriting between cache instance.

looking into the options, I found

generate a unique random folder name (not helpful when trying to understand the contents)

w $SYSTEM - gives DESKTOP-VN0HNSP:KEVDEV (not unique enough ?)

w $SYSTEM.INetInfo.LocalHostName()  - generates DESKTOP-VN0HNSP -this is the first part of $SYSTEM (could change by renaming the computer)

w $SYSTEM.INetInfo.EthernetAddress() - generates 000C292678A - ie mac address (liable to change if the card goes down - what happens on two network cards being installed ?)

w $SYSTEM.INetInfo.HostNameToAddr($SYSTEM.INetInfo.LocalHostName())  - generates 10.0.0.49 (could change, but unlikely - certainly in our network)

the last one generates the IPaddress that the system is installed on but relies on the LocalHostName() to get that number

is there any risks associated with the LocalHostName() call.

can I obtain the IPAddress any other way without using the LocalHostName()  ?

I'm using windows today, but is there any issues if we suddenly swap to linux ? - being a $system call, I assume not

suggestions please.

kevin

  • 0
  • 0
  • 214
  • 4
  • 3

Answers

Kevin

You can also use a Command Pipe (docs) and read directly from your OS using IPconfig  (on Windows) or ifconfig (in Linux/ Unix)

You just do the usual OPEN + USE and READ whatever comes back.

As an example a handcrafted ping routine

zping ;
 k empty
 s pipe="|CPIPE|"
 close pipe
 s ping="ping 10.10.12."_p
 open pipe:(ping):10 w $t," ",p,!
 for  {
 use pipe read line
 use 0
 set empty=$s($l(line):0,1:$i(empty)) q:empty>3
 write:empty<2 line,!
 }

Robert, I think there's a mistake in the 5rh line whereby variable "p" is undefined.

s ping="ping 10.10.12."_p

the thing about this code is that you have to know the first part of the IPaddress you are pinging, and thats part of what I want to automate

kevin

Sorry Kevin,
I concentrated on CPIPE.

my code was Written for a FOR p=1:1:254 loop to find unused IP addresses in a specific subnet.

in your case, ping might be something like  set ping= "ipconfig"

How about this?

set guid=##class(%SYS.System).InstanceGUID()

Documentation is here.

Thanks John.

Although unique string is indeed generated ( for instance 1328BACC-D8A5-46C7-BACC-19634E0F83A2 ), its not a very memorable directory name and so, in my head, I'd dismissed the instanceGUID.

I would need to keep track of which machine/instance "1328BACC-D8A5-46C7-BACC-19634E0F83A2" is being generated to instantly know the content. of any given folder.

kev

Hello Kevin,

if I anderstand you correctly, several your Cache systems (development, life, ...) will store their files on a third server (possibly on a file server) and you want to put the files from each (source) Cache (instance) into a different (target) folder, where the folder name being the "name" of the source Cache system - am I correct?

If yes, I think, your best choice ist:

...\hostNameOfCache\instanceNameofCache...

or, as John Murray suggested

...\GUIDofCacheInstance...

or just a fixed string like

...\kevinNotebook(development)...

You can put (John's) GUID or my "fixed string"
in a (possibly system) Global like ^%Zconfig("path")=...

Why?
Things like MAC- or IP-Addresses can change more often then you think. Especially IP-Addresses will change, hence are there DNS servers.

On the other hand, it's uncommon to change host- or instance names (of Cache or of whatever installation).

Your IP-Address preference has an other downside too. Many servers have more then one IP-Address (and if they do not have one today, maybe tomorrow!).

If you persist to take the systems IP-Address, here is, what you wanted:

set iplist = $system.INetInfo.GetListOfConfiguredInterfaces(0)
for i = 1:1:$listlength(iplist) zw $list(iplist,i)

Regards and
have a nice day
Julius

Julius,

hadn't thought of multiple network cards, and of multiple ip address's.

your last bit of two-line code  has forced me think again. I'm assuming the ip address would be from the actual network address that the call to the server is made from. so I would be putting, what should be "common" files into two separate directories if use the ipAddress.

many thanks.