Every now and again, I need to start the Django development server, and have it viewable by other machines on my network, as described here:
http://docs.djangoproject.com/en/dev/ref/django-admin/#runserver
My machine’s IP address tends to change every now and again, so I’d like to have a little shell alias or something that spits out the manage.py command with my machine’s current IP address, maybe like this:
python manage.py runserver $(COMMAND TO FIND MY MACHINE’S IP ADDRESS GOES HERE):8000
This checks your default interface, and use that to retrieve your primary ip. Helpful when you have many interfaces, and tons of virtual ip addresses:
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):
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):
To get the ip of another machine that you know the name of, try (replace hostname and 192.168.111 with your own values):
ifconfig
is probably what you're after. You'll need to either run it throughgrep
to filter out some of the noise though.