While your question implies the usage of a mouse in a GUI to get the IP address, an easy way from the terminal/command line is to use a combo of ifconfig
and grep
like this; note I am showing my actual output but changing IP addresses connected to me to 123.456.789.1
for this example:
ifconfig | grep "inet "
And that would return something like this:
inet 127.0.0.1 netmask 0xff000000
inet 123.456.789.1 net mask 0xffffc000 broadcast 123.456.127.255
inet 192.168.56.1 netmask 0xffffff00 broadcast 192.168.56.255
The first address of 127.0.0.1
is the localhost
loopback address, 123.456.789.1
is the address connected to en0
on my Mac Mini (aka: the main Ethernet port) and the 192.168.56.1
is vboxnet0
which is connected to my local install of VirtualBox.
But that can be confusing if you definitely just want a clean IP address. If you know the interface name of the connection you need an IP address from you can just run this command; let’s assume you want en0
which is the main Ethernet port on my Mac Mini:
ipconfig getifaddr en0
The output would be a clean IP address like this:
123.456.789.1
Which is nicer to use and read in scripts.
Now how would you know your interface name? Easy! Just run ifconfig
without any parameters like this:
ifconfig
And the output would be something like this:
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
options=10b<RXCSUM,TXCSUM,VLAN_HWTAGGING,AV>
ether aa:bb:cc:dd:ee:ff
inet6 fe80::ab12:cd34:ef56:aba2%en0 prefixlen 64 scopeid 0x4
inet 123.456.789.1 net mask 0xffffc000 broadcast 123.456.127.255
nd6 options=1<PERFORMNUD>
media: autoselect (100baseTX <full-duplex>)
status: active
bridge0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
options=63<RXCSUM,TXCSUM,TSO4,TSO6>
ether aa:20:66:d1:18: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: en3 flags=3<LEARNING,DISCOVER>
ifmaxaddr 0 port 6 priority 0 path cost 0
nd6 options=1<PERFORMNUD>
media: <unknown type>
status: inactive
vboxnet0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
ether 0a:00:27:00:00:00
inet 192.168.56.1 netmask 0xffffff00 broadcast 192.168.56.255
And yes, that can seem like a daunting wall of gibberish, but basically look for the items like en0:
and then look for the inet
connected to that. Once you have confirmed with interface name you need an IP address from, the whole setup of ipconfig getifaddr en0
will it easier to get an IP address moving forward.