When you connect to your iPhone's personal hotspot, your WiFi icon changes from the signal strength "V" to a chain link. Such as in the image copied from another StackExchange question below:
I've written a script which can figure out what network interface is being used (out of the 14 or so that I get back from the route, ifconfig, and networksetup commands), but nothing that I can see in those would help differentiate a regular WiFi from a hotspot connection. The best I've been able to do so far is presume that if I'm on WiFi and the network gateway is 172.20.*, then I know it must be my iPhone.
I'm wondering to determine if I'm on a hotspot since the Mac obviously knows because of the icon it is using for the connection.
Can a program or script tell this on macOS Ventura 13.2.1?

networksetup -getairportnetwork enXwhereXis the identifier of the hardware device (i.e.en0is WiFi on a MacBook Pro). – Allan Mar 24 '23 at 20:46