54👍
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'
15👍
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?
- [Django]-Django REST Framework: how to substitute null with empty string?
- [Django]-Use only some parts of Django?
- [Django]-Django, how to remove the blank choice from the choicefield in modelform?
7👍
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̶ ̶
- [Django]-Django: TypeError: 'tuple' object is not callable
- [Django]-Detect whether Celery is Available/Running
- [Django]-Datetime and timezone conversion with pytz – mind blowing behaviour
- [Django]-Django: For Loop to Iterate Form Fields
- [Django]-Multiple pages using Reportlab – Django
- [Django]-Iterating through two lists in Django templates
5👍
Folks are using character counts to pull the right columns from the ip address line, but using spaces as a delim makes this more scalable to different length ip addresses…
ifconfig en1 | grep inet | grep -v inet6 | cut -d" " -f2
- [Django]-What's the difference between Model.id and Model.pk in django?
- [Django]-Dropdown in Django Model
- [Django]-Django admin: separate read-only view and change view
4👍
This is a quick and dirty way, that works under OSX
/sbin/ifconfig | grep 'inet ' | grep -v '127.0.0.1' | head -n1 | awk '{print $2}'
Basically get all interfaces with an IPV4 address, skip localhost and then get the first interface.
Also, use path to ifconfig. I have seen to many shell script brake when used from ex. cron because of PATH failure.
- [Django]-Gunicorn autoreload on source change
- [Django]-Django edit user profile
- [Django]-Running Scrapy spiders in a Celery task
4👍
On Mac OS X 10.11.6 El Capitan (and probably older releases), you can print your IP with
ipconfig getifaddr <device>
where <device>
is en0
, en1
, etc.
- [Django]-Django model naming convention
- [Django]-Feedback on using Google App Engine?
- [Django]-Django : mysql : 1045, "Access denied for user
3👍
ifconfig
is probably what you’re after. You’ll need to either run it through grep
to filter out some of the noise though.
- [Django]-How to use python2.7 pip instead of default pip
- [Django]-Django project root self discovery
- [Django]-Set Django set Integer Field minimum to 1
3👍
The following command works perfectly for me on RHEL 6.3:
ifconfig | grep -v '127.0.0.1' | sed -n 's/.*inet addr:\([0-9.]\+\)\s.*/\1/p'
- [Django]-Turn off automatic pagination of Django Rest Framework ModelViewSet
- [Django]-Django templates syntax highlighting in Eclipse
- [Django]-110: Connection timed out (Nginx/Gunicorn)
3👍
Simple Command to find IP Address with default interface.
ip -o route get "8.8.8.8" 2>/dev/null | sed -e 's/^.* src \([^ ]*\) .*$/\1/'
or
ip route | grep src | awk -F 'src' '{print $NF; exit}' | awk '{print $1}'
or
ip route | sed -n 's/.* src \(.*\) metric .*/\1/p' | uniq
Tested on All Unix OS
- [Django]-Usage of .to_representation() and .to_internal_value in django-rest-framework?
- [Django]-Inject errors into already validated form?
- [Django]-Django when to use teardown method
2👍
This may not be as elegant as some of the other solutions, but it works on Linux systems and is more comforting to look at than a regex:
ifconfig eth0 | grep 'inet addr:' | awk '{print $2}' | awk -F ':' '{print $2}'
- [Django]-Django Overriding Model Clean() vs Save()
- [Django]-Django : Is it impossible to static tag into block tag?
- [Django]-Dlopen() failed to load a library: cairo / cairo-2
1👍
Try this (if you are an Arch user)
resolveip -s $HOSTNAME
Alternative
For getting IPv4 adress you can use:
host $(uname -n) | grep "address" | grep -v "IPv6" | head -n 1 | awk '{print $4}'
For getting IPv6 one:
host $(uname -n) | grep "IPv6 address" | head -n 1 | awk '{print $5}'
You can replace $(uname -n) with $(hostname) if you’d like.
- [Django]-What is "swappable" in model meta for?
- [Django]-How to make Django's devserver public ? Is it generally possible?
- [Django]-Internationalisation Django (on OSX)
0👍
Here a solution to find the current IP address:
route -n get default|grep interface|awk ‘{ print $2 }’|xargs ipconfig getifaddr
tested on Mac only.
- [Django]-Django, Retrieve IP location
- [Django]-How to server HTTP/2 Protocol with django
- [Django]-How do I pass a PK or slug to a DetailView using RequestFactory in Django?
0👍
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:
netstat -rn | gawk '/UG/ {print $NF}' | xargs ifconfig | gawk 'match($0,/inet addr:(.*) B/,a) {print a[1]}'
- [Django]-Django Multiple Authentication Backend for one project
- [Django]-Access instance passed to ModelForm from clean(self) method
- [Django]-How to delete project in django
0👍
Recap: if you’d like to copy/paste
to command line and just get the network IP address, here’s what works on Mac (on WiFi):
echo $(ifconfig en0 | grep inet | grep -v inet6 | cut -d" " -f2)
Here is assigning it to bash script variable:
LOCAL_IP=$(ifconfig en0 | grep inet | grep -v inet6 | cut -d" " -f2)
This is based on answers by Valentin Rocher and Matt Kropmton
- [Django]-Matplotlib – Tcl_AsyncDelete: async handler deleted by the wrong thread?
- [Django]-Unique fields that allow nulls in Django
- [Django]-Django dumpdata django.contrib.auth
0👍
Tested on Archlinux
only:
ifconfig $(route | awk '{if($1=="default") print $NF}') | awk '{if($1=="inet") print $2}'
Get the default interface with route
, get the ip address of interface with ifconfig
.
Because the command syntax or output may vary, you may need to change for works on your system.
- [Django]-Multiple Models in a single django ModelForm?
- [Django]-Project design / FS layout for large django projects
- [Django]-Group by Foreign Key and show related items – Django
0👍
On Android Shell, I’m tried:
ifconfig eth0 | grep 'inet addr' | tr -d '^[A-Za-z]+$' | tr -s ':' | cut -d ':' -f 2
- [Django]-How do I refresh the values on an object in Django?
- [Django]-Are there any plans to officially support Django with IIS?
- [Django]-Django: display time it took to load a page on every page
-1👍
On Ubuntu( and Debian like distro)
to see your local IP address:
hostname -I | awk '{print $1}'
to see your Global IP address:
curl -4 icanhazip.com
curl ifconfig.co //this responds faster
to see all information about your(or any)IP address:
whois $(curl ifconfig.co)
assumed you have installed whois
on your machine, if it’s not:
sudo apt-get install whois
- [Django]-How to set django model field by name?
- [Django]-How to translate docker-compose.yml to Dockerrun.aws.json for Django
- [Django]-How to add url parameters to Django template url tag?