How do I find my computer's IP address using the bash shell?
ifconfig en0 | grep inet | grep -v inet6
Output of above is expected to be in the following form:
inet 192.168.111.1 netmask 0xffffff00 broadcast 192.168.111.255
Add an awk statement to print the second column to avoid using cut (awk is a pretty standard unix tool):
ifconfig en0 | grep inet | grep -v inet6 | awk '{print $2}'
I use the following to get the current IP when on a LAN where the first few numbers of the IP are always the same (replace 192.168.111 with your own numbers):
ifconfig | grep 192.168.111 | awk '{print $2}'
To get the ip of another machine that you know the name of, try (replace hostname and 192.168.111 with your own values):
ping -c 1 hostname | grep 192.168.11 | grep 'bytes from' | awk '{print $4}' | sed 's/://g'
You might already be aware, but running
python manage.py runserver 0.0.0.0:8000
makes your machine visible to everyone on the network.
Is there a reason you'd need to specify your IP?
Thi should work as well as other commands I've already seen:
ifconfig eth0 | grep inet | awk '{print $2}' | cut -d':' -f2
- Replace eth0 with the desired interface (eth0, eth1, wlan0...)
I̶ ̶t̶h̶i̶n̶k̶ ̶y̶o̶u̶ ̶c̶a̶n̶ ̶a̶l̶s̶o̶ ̶w̶r̶i̶t̶e̶:̶
̶ ̶ ̶ ̶h̶o̶s̶t̶n̶a̶m̶e̶ ̶-̶I̶ ̶|̶ ̶c̶u̶t̶ ̶-̶d̶'̶ ̶'̶ ̶-̶f̶1̶ ̶