Mac - Computer Name - Omnis 11.1 - OS Sequoia -- using bonjour to find things on a local network instead.
Doug Easterbrook
doug at artsman.com
Thu Oct 3 16:49:49 UTC 2024
hi Michael.
I will share this code with you. it is written using Kelly’s TCP tools to look for network services on the mac. The code as written, will scan your entire network looking for postgres databases across the local network using bonjour services. The key two lines are below. We’ve used this for over a decade to make it easier to find postgres installations on networks and connect — no headache for the user.
the whole idea is to ask whats out there, rather than going looking or it on each machine. as in ‘hey, printers, where are you’. or ‘hey, psotgres, where are you’
it can be used to find SMB servers, and printers (samples also below). It can be used to find other things, I just do not know the name of all the services.
its based on asking the network whats available.
# Look for the TCP address of the database using bonjour if it is enabled. Easy on Mac's. PC's need Bonjour services
Calculate serviceType as '_postgresql._tcp.'
Calculate serverList as TCPTools.$getnetservices(serviceName,serviceType)
It is easy enough to turn on bonjour on a mac. I DO NOT KNOW is the odb server announces itself advertises as a specific bonjour service, so the trick becomes finding a way to announce the machine via bonjour.
one way might be name the SERVER as something you know. so you could call it ’server.local’. or ‘odbserver.local’ and then find the name of the server looking for ‘file seervers'
if you can figure out what the serviceType is for file services or machine announcing themselves … and then you’d know, for any machine, where the server was and automatically find it.
For example, this finds all bonjour printers on my network. very handy.
Calculate serviceType as '_ipp._tcp.'
Calculate serverList as TCPTools.$getnetservices(serviceName,serviceType)
For example, this found all 5 SMB file servers on my network. it identified al time machine servers, an SMB server on freenas (unix), and my own mahcine.
Calculate serviceType as '_smb._tcp.'
Calculate serverList as TCPTools.$getnetservices(serviceName,serviceType)
there are a lot more services than that .. these are ones I guessed at.
the kind of information returned
— service name
— host name
— host ip number
— port that the machine is responding on for that service
It is possible to turn on Bonjour on a windows machine. There were instructions we found for it a while back on stack overflow, so I know it works. it means installing some software from apple on the server. look up in stack overflow if this whole idea has merit for you.
finally, do I have documentation for kelly's xcomp?
no. I wrote my code to use his xcomp well over a decade ago and I don’t exactly recall the data. So, you’d also need Kelly’s TCP xComp for to make this idea work.
in my humble opinion, very very useful.
here’s the entire thing — that looks for postgres servers
# This routine finds postgres servers that are available to us using bonjour servers. if there is only one, it will put up that ip address and return it.
#
# Parameters
# pIPaddress->return the ipAddress of the machine with the postgres server
# pPort->return the port of the machine with the postgres server
# pFieldRef->reference to the location where we want to popup the list
Do serverList.$define(serviceName,serviceRef,hostName,hostIPnum,hostPortnum)
If I_DOS_MACHINE
# no bonjour on DOS machines -- no support for it in TCPtalk
Quit method kFalse
End If
# Look for the TCP address of the database using bonjour if it is enabled. Easy on Mac's. PC's need Bonjour services
Calculate serviceType as '_postgresql._tcp.'
Calculate serverList as TCPTools.$getnetservices(serviceName,serviceType)
Switch serverList.$linecount
Case 0
# there is no lines in the server list, so the user has to know it
# Calculate pIPaddress as ''
# Calculate pPort as 5432 ## return the default port
Quit method kFalse
Case 1
# there is only one postgres server that we can find, so lets default to that
Calculate serverList.$line as 1
Do method selectDBserver (serverList,pIPaddress,pPort)
Quit method kTrue
Default
Do selectServerList.$define(hostName)
Do method findLocalIPAddress
For serverList.$line from 1 to serverList.$linecount
Calculate hostName as TCPTools.$ipnumtostring(serverList.hostIPnum)
If left(hostName,4)='169.'|hostName=iLocalIPAddress
Calculate hostName as '127.0.0.1'
End If
Calculate hostName as con(serverList.hostname,':',serverList.hostPortnum,' (',hostName,')')
Do selectServerList.$add(hostName)
End For
End Switch
# there is more than one postgres server on the network, so pop up the list and let the user pick one.
If pFieldRef
Set reference container to pFieldRef.$wind
Calculate x as pFieldRef.$left+container.$left
Calculate y as pFieldRef.$top+container.$top+30
Popup menu from list selectServerList at x,y
Else
Popup menu from list selectServerList at
End If
Switch selectServerList.$line
Case 0
Quit method kFalse
Default
Calculate serverList.$line as selectServerList.$line
Do method selectDBserver (serverList,pIPaddress,pPort)
Quit method kTrue
End Switch
Doug Easterbrook
Arts Management Systems Ltd.
mailto:doug at artsman.com
http://www.artsman.com
Phone (403) 650-1978
> On Oct 3, 2024, at 8:42 AM, Michael Mantkowski <michaelj at clientrax.com> wrote:
>
> I am actually after the Servers IP Address in the end.
>
> This whole thing comes up when we are using the Omnis Data Bridge on the Mac.
>
> We want to Ping the Server to make sure it is on the network.
>
> But we need to make sure we are not on the server as TCPPing does not work local.
>
> *********************************************************************
> Michael Mantkowski
> ClienTrax Software
> 1-614-875-2245
> *********************************************************************
>
>
> -----Original Message-----
> From: omnisdev-en On Behalf Of Doug Easterbrook via omnisdev-en
> Sent: Thursday, October 3, 2024 11:15 AM
> To: OmnisDev List - English <omnisdev-en at lists.omnis-dev.com>
> Cc: Doug Easterbrook <doug at artsman.com>
> Subject: Re: Mac - Computer Name - Omnis 11.1 - OS Sequoia
>
> hi Michael.
>
> I know that the question starts with getting the computer name….. but then the side track seems to really be about getting the ip address of the computer
>
>
>
> I use two ways to get the local ip address of the machine on OSX
>
> the built in method — which returns the primary IP address and is usually correct
>
> TCPGetMyAddr Returns iLocalIPAddress
>
>
> OR if I want more, I use Kelly Burgess’s TCP tools to grab the list of interfaces, and what it thinks is the local ip address.
>
> Calculate iInterfaceList as TCPTools.$interfacelist() Calculate iLocalIPAddress as TCPTools.$localip()
>
> The first command will return you all active interfaces, from ether net card, to wifi, to VPN’s that are available to the computer since things can be multi homed these days.
>
> Trouble is with getting the machines IP address these days, is that each machine may have many, and they can be ipv4 or ipv6
>
>
>
>
> As far as the getEnv command goes, it still works as we use it to get the home directory for mac and windows. You can see what values are available if you go into the terminal and type ‘env’.
>
>
> turns out 'ComputerName’ is no longer one of those things. The following command will get you the computer name in terminal.
>
>
>
> scutil --get LocalHostName
>
> All you have to do is wrap that in applescript if you want it as below (I just verified in on my sequoia machine with studio 11.2)
>
> Calculate applescript as 'do shell script "scutil --get LocalHostName" '
> Do $runapplescript(applescript,result,errorText)
>
>
>
>
>
> I know you have a specific reason for doing this. Since you are sending it a server, I’m guessing it is to track users, logins or what have you. Depending on the back end database you are using (eg postgres), there are ways to get this from the server itself.
>
>
>
>
>
>
>
>
> Doug Easterbrook
> Arts Management Systems Ltd.
> mailto:doug at artsman.com
> http://www.artsman.com
> Phone (403) 650-1978
>
>> On Oct 3, 2024, at 6:56 AM, Michael Mantkowski <michaelj at clientrax.com> wrote:
>>
>> Thanks Phile and Nigel,
>>
>> I will try this and report back.
>>
>> Michael
>>
>> *********************************************************************
>> Michael Mantkowski
>> ClienTrax Software
>> 1-614-875-2245
>> *********************************************************************
>>
>>
>> -----Original Message-----
>> From: omnisdev-en On Behalf Of Phil (OmnisList)
>> Sent: Thursday, October 3, 2024 9:54 AM
>> To: omnisdev-en at lists.omnis-dev.com
>> Subject: Re: Mac - Computer Name - Omnis 11.1 - OS Sequoia
>>
>> Michael,
>>
>> Begin text block
>> Text:computer name of (system info)
>> Get text block lvScript
>> Do $runapplescript(lvScript,lcComputerName)
>>
>> or for an IP address:
>>
>> Calculate lcApScript as 'set myip to do shell script "'
>> Calculate lcApScript as con(lcApScript,"ifconfig | grep 'broadcast' |
>> awk '{print $2}'") Calculate lcApScript as con(lcApScript,'"') Do
>> $runapplescript(lcApScript,lcIP_Address)
>> If pos(kCr,lcIP_Address)
>> Calculate lcIP_Address as mid(lcIP_Address,1,pos(kCr,lcIP_Address)-1)
>> End If
>> Do replaceall(lcIP_Address,'"','') Returns lcIP_Address
>>
>>
>> regards
>> Phil Potter
>> Based in Chester in the UK.
>>
>> On 03/10/2024 13:48, Michael Mantkowski wrote:
>>> We upgraded one of our Mac clients to Omnis 11.1 yesterday after they
>>> had
>> upgraded their Mac OS to Sequoia and Omnis 4.3.2.1 would no longer
>> work for them.
>>>
>>> Running into an issue with getting the computer name of the
>>> workstation
>> they are on. We had been using the code below to find it. It no longer
>> seems to work and the built in Omnis getenv() also does not work.
>>>
>>> Anyone know how to do this with newer Mac OS version?
>>>
>>>
>>> f inMac
>>> Do code method CodeClass/RunMacShell ("grep '<key>ComputerName</key>'
>> /Library/Preferences/SystemConfiguration/preferences.plist -A 1 | grep
>> '<string>' ") Returns lvReturn
>>> Calculate lvReturn as mid(lvReturn,pos('>',lvReturn)+1)
>>> Calculate ctComputerName as mid(lvReturn,1,pos('<',lvReturn)-1)
>>> Else
>>> Calculate ctComputerName as getenv("COMPUTERNAME") End If
>>>
>>>
>>> This is all used to eventually get the IP Address of the local
>>> workstation
>> and the database server so that we can Ping it for online verification.
>> Since the above fails the Ping Fails as well. I ended up having to
>> disable the whole server verification to get them running last night.
>>>
>>>
>>> *********************************************************************
>>> Michael Mantkowski
>>> ClienTrax Software
>>> 1-614-875-2245
>>> *********************************************************************
>>>
>>>
>>>
>>> _____________________________________________________________
>>> Manage your list subscriptions athttps://lists.omnis-dev.com Start a
>>> new message ->mailto:omnisdev-en at lists.omnis-dev.com
>> _____________________________________________________________
>> Manage your list subscriptions at https://lists.omnis-dev.com Start a
>> new message -> mailto:omnisdev-en at lists.omnis-dev.com
>>
>> _____________________________________________________________
>> Manage your list subscriptions at https://lists.omnis-dev.com Start a
>> new message -> mailto:omnisdev-en at lists.omnis-dev.com
>
> _____________________________________________________________
> Manage your list subscriptions at https://lists.omnis-dev.com Start a new message -> mailto:omnisdev-en at lists.omnis-dev.com
>
More information about the omnisdev-en
mailing list