identifying current LAN ip address from terminal - 12/01/14 09:01 PM
Code:
MAC:~ virtual1 $ ifconfig lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384 options=3<RXCSUM,TXCSUM> inet6 ::1 prefixlen 128 inet 127.0.0.1 netmask 0xff000000 inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1 nd6 options=1<PERFORMNUD> gif0: flags=8010<POINTOPOINT,MULTICAST> mtu 1280 stf0: flags=0<> mtu 1280 en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500 ether 78:31:c1:d4:d8:16 inet6 fe80::7a31:c1ff:fed4:d816%en0 prefixlen 64 scopeid 0x4 inet 10.15.0.208 netmask 0xffff0000 broadcast 10.15.255.255 nd6 options=1<PERFORMNUD> media: autoselect status: active en1: flags=8963<UP,BROADCAST,SMART,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1500 options=60<TSO4,TSO6> ether 72:00:02:e6:f9:80 media: autoselect <full-duplex> status: inactive en2: flags=8963<UP,BROADCAST,SMART,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1500 options=60<TSO4,TSO6> ether 72:00:02:e6:f9:81 media: autoselect <full-duplex> status: inactive bridge0: flags=8822<BROADCAST,SMART,SIMPLEX,MULTICAST> mtu 1500 options=63<RXCSUM,TXCSUM,TSO4,TSO6> ether 7a:31:c1:4d:9b:00 Configuration: id 0:0:0:0:0:0 priority 0 hellotime 0 fwddelay 0 maxage 0 holdcnt 0 proto stp maxaddr 100 timeout 1200 root id 0:0:0:0:0:0 priority 0 ifcost 0 port 0 ipfilter disabled flags 0x2 member: en1 flags=3<LEARNING,DISCOVER> ifmaxaddr 0 port 5 priority 0 path cost 0 member: en2 flags=3<LEARNING,DISCOVER> ifmaxaddr 0 port 6 priority 0 path cost 0 media: <unknown type> status: inactive p2p0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 2304 ether 0a:31:c1:d4:d8:16 media: autoselect status: inactive utun0: flags=8051<UP,POINTOPOINT,RUNNING,MULTICAST> mtu 1380 inet6 fe80::e1a1:3f66:87bd:db95%utun0 prefixlen 64 scopeid 0xa inet6 fd58:e0cd:efe3:3d3c:e1a1:3f66:87bd:db95 prefixlen 64 nd6 options=1<PERFORMNUD> en4: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500 options=10b<RXCSUM,TXCSUM,VLAN_HWTAGGING,AV> ether a8:20:66:28:87:0b inet6 fe80::aa20:66ff:fe28:870b%en4 prefixlen 64 scopeid 0x7 inet 10.3.24.143 netmask 0xffff0000 broadcast 10.3.255.255 nd6 options=1<PERFORMNUD> media: autoselect (1000baseT <full-duplex>) status: active
ok that's pretty useful, but let me narrow it down
Code:
en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500 ether 78:31:c1:d4:d8:16 inet6 fe80::7a31:c1ff:fed4:d816%en0 prefixlen 64 scopeid 0x4 inet 10.15.0.208 netmask 0xffff0000 broadcast 10.15.255.255 nd6 options=1<PERFORMNUD> media: autoselect status: active en4: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500 options=10b<RXCSUM,TXCSUM,VLAN_HWTAGGING,AV> ether a8:20:66:28:87:0b inet6 fe80::aa20:66ff:fe28:870b%en4 prefixlen 64 scopeid 0x7 inet 10.3.24.143 netmask 0xffff0000 broadcast 10.3.255.255 nd6 options=1<PERFORMNUD> media: autoselect (1000baseT <full-duplex>) status: active
Close. Now... one is my airport, and one is my ethernet. Which one is my primary (listed at the top in the Network prefs) - i.e. where my traffic is going out on?
In this specific case, en4 is actually my primary, I'm using a TB/Enet adapter on the retina. en0 is the wifi, which is placed below ethernet in my list.
So how do I tell my script to figure out which one is primary? (en4 in this case) Note that wifi is turned on, which is why status is "active". Wifi will sometimes be active when ethernet is the primary, so "active" isn't sufficient to identify primary. I cannot rely on any consistency with the adapter name ("enXXX") I need to know which is primary.
Any suggestions? I'm not limited to ifconfig and I can explore, I just need to know what to query. systemsetup doesn't have it...